Merhaba beyler yardiminiza ihtiyacim var. Henuz yeniyim bunu nasil yapacagim ?
Soru: Update test.html by adding a button to zero counter
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>
My First WEB Page
</title>
<script>
// var counter = 0;
// var onCounterClick = function() {
// counter += 1; // counter = counter + 1;
// var h1 = document.getElementById("counterH1");
// h1.innerHTML = "You've clicked " + counter + " times.";
// return counter;
// };
function seqGen(start) {
let counter = start - 1;
let gen = function(reset) {
if (reset == true) {
counter = start - 1;
} else {
counter += 1;
}
return counter;
};
return gen;
}
const s1 = seqGen(1);
function updateDisplay(counter) {
let h1 = document.getElementById("counterH1");
h1.innerHTML = "You've clicked " + counter + " times.";
}
function onCounterClick() {
updateDisplay(s1(false));
}
function onCounterReset() {
updateDisplay(s1(true));
}
</script>
</head>
<body>
<h1 id="counterH1">You've clicked 0 times.</h1>
<input type="button" value="Click me"
onclick="onCounterClick()"/>
<br/>
<input type="button" value="Reset"
onclick="onCounterReset()"/>
</body>
</html>