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_f.html
33 lines ASCII Windows (CRLF)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JS While F</title>
</head>
<body>
<h1>JS While F</h1>
<input type="number" id="inputRuta1" placeholder="Skriv in tal 1">
<input type="number" id="inputRuta2" placeholder="Skriv in tal 2">
<button onclick="myFunction()">Klicka mig</button>
<br><br>
<div id="divRuta"></div>
<script>
let inputRuta1 = document.getElementById("inputRuta1");
let inputRuta2 = document.getElementById("inputRuta2");
let textRuta = document.getElementById("divRuta");
function myFunction() {
let i = parseInt(inputRuta1.value);
let end = parseInt(inputRuta2.value);
let resultat = 0;
while (i <= end) {
resultat += i;
console.log(i);
console.log(resultat);
i++;
}
textRuta.innerHTML = resultat.toString();
}
</script>
</body>
</html>