Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion 01/app.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
const randomNumber = Math.round(Math.random() * 20);
console.log(randomNumber);
console.log("Wylosowana liczba to: " + randomNumber);

if(randomNumber > 5) {
for (let i = 5; i <= randomNumber; i++) {
console.log(i);
}
} else {
console.log("Wylosowana liczba jest zbyt mała, aby użyć pętli.");
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

22 changes: 21 additions & 1 deletion 02/app.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
const x = 5;
let result = 0;
let result = 0;

for (let i = 1; i <= x; i++) {
console.log("result = " + result + "+" + i);
result = result + i;
}

console.log("Ostateczna suma to: " + result);

console.log("Za pomocą pętli while:");

result = 0;
let i = 1;

while (i <= x) {
console.log("result = " + result + "+" + i);
result = result + i;
i++;
}

console.log("Ostateczna suma to: " + result);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

2 changes: 1 addition & 1 deletion 02/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>JavaScript: Podstawy, pętle #02 - devmentor.pl</title>
</head>
<body>
<body>
<script src="./app.js"></script>
</body>
</html>
9 changes: 8 additions & 1 deletion 03/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
const x = 10;
let iteration = 0;
let randomNumber = -1;
let randomNumber = -1;

while (randomNumber !== x) {
randomNumber = Math.round(Math.random() * 10);
iteration++;
}

console.log("Pętla potrzebowała " + iteration + " prób, żeby wylosować podaną liczbę.");

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍