a couple of loops

This commit is contained in:
Geir Okkenhaug Jerstad 2024-08-27 14:38:00 +02:00
parent 12dc3057b6
commit 5868ff1a7a
5 changed files with 35 additions and 0 deletions

View file

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div>
<div id="text">Tekst her</div>
<button onclick="change()">Trykk her</button>
Vis dyr: <input id="showAnimal" onchange="show()"></button>
<div id="show"></div>
</div>
<script>
function change() {
let animalList = ["hund", "katt", "esel"];
let animal = animalList[Math.floor(Math.random() * animalList.length)];
document.getElementById('text').innerHTML = `${animal}`;
}
function show(){
let animal = document.getElementById('showAnimal').value;
document.getElementById('show').innerHTML = `${animal}`;
}
</script>
</body>
</html>

View file

@ -0,0 +1,5 @@
for (let i = 0; i <= 9; i++){
if (i % 2 !== 0) console.log(i);
}
let i = 0;
while (i < 10) { console.log(i); i++; }