Show sourcecode
The following files exists in this folder. Click to view.
public_html/gamla-kurser/webbutv2/övningar/js_while/
js_while_a.html
js_while_b.html
js_while_c.html
js_while_d.html
js_while_e.html
js_while_f.html
js_while_g.html
js_while_h.html
js_while_i.html
js_while_h.html
38 lines ASCII Windows (CRLF)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JS While H</title>
</head>
<body>
<h1>JS While H</h1>
<input type="number" id="numberInput" placeholder="Skriv in ett tal">
<button onclick="myFunction()">Klicka mig</button>
<div id="divRuta"></div>
<script>
let numberInput = document.getElementById("numberInput");
let textRuta = document.getElementById("divRuta");
function myFunction() {
textRuta.innerHTML = "";
let i = 1;
let count = 1;
while (count <= 100) {
if (i % numberInput.value === 0) {
textRuta.innerHTML += i + ", ";
if (count % 10 === 0) {
textRuta.innerHTML += "<br>";
count++;
}
else {
count++;
}
}
i++;
}
console.log(count);
}
</script>
</body>
</html>