Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions 01/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function showTime() {
const time = new Date().toLocaleTimeString();
console.log(time);
}

showTime();
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.

👍

5 changes: 5 additions & 0 deletions 02/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function sayHello(name) {
name = "devmentor.pl!";
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.

Tutaj jest błąd sam parametr przyjmuje jakaś wartość - nie należy go nadpisywać. Ta linia jest niepotrzebna.

console.log(`czesc ${name}`);
}
sayHello(name);
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.

Dopiero tutaj definiujemy wartość dla parametru - powinno być sayHello("devmentor.pl") w takiej sytuacji niejawnie mamy przypisanie tj. name = "devmentor.pl"

3 changes: 3 additions & 0 deletions 03/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function () {
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.

Czyli zaczynamy od czegoś takiego const sum = function() { ... } - reszta jak do tej pory.


}
27 changes: 27 additions & 0 deletions 04/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
let counter = 1;
let counterTwo = 1;
let idInterval;
let stopTime;

function runTime() {
const time = new Date().toLocaleTimeString();
console.log(time);

const showTimeCounter = function () {
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.

Ta funkcje nigdy nie jest uruchamiana więc nie zatrzymasz odliczania, powinno być bez niej tj.

counterTwo++;
if (counterTwo > 5) {
    clearInterval(stopTime);
}

PS. IDE oznacza, że funkcja nie jest uruchamiana:
Screenshot 2024-04-15 at 06 37 43

counterTwo++;
if (counterTwo > 5) {
clearInterval(stopTime);
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.

Trzeba jeszcze tylko podmienić odpowiednią nazwę zmiennej: clearInterval(idInterval);

}
};
}
const showCounter = function () {
console.log(counter);
counter++;

if (counter > 5) {
clearInterval(idInterval);
}
};

idInterval = setInterval(showCounter, 2000);
stopTime = setInterval(showCounter, 2000);
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.

NIe wiem dlaczego tutaj uruchamiasz 2 razy tą samą funkcję. Zostawmy pierwsze uruchomienie i podmieńmy nazwę funkcji tj.
idInterval = setInterval(runTime, 2000);

4 changes: 3 additions & 1 deletion 04/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<title>JavaScript: Podstawy, funkcje #04 - devmentor.pl</title>
</head>
<body>
<script src="./app.js"></script>

<script src="../04/scrypt.js"></script>
<script src="./ap.js"></script>
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.

Dlaczego tutaj coś zmieniałeś? Powinno być ./app.js jak w pozostałych. Może był problem ze sposobem uruchomienia live servera?

</body>
</html>