loops uke 5

This commit is contained in:
Geir Okkenhaug Jerstad 2024-09-04 14:56:03 +02:00
parent 484bde716b
commit 69ce8cd8a6
5 changed files with 128 additions and 2 deletions

View file

@ -0,0 +1,32 @@
<!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>Numbers tested: <br><div id="num"></div>
<div id="display"></div>
<button onclick="generateRandom()">generer nummer</button>
</div>
<script>
function generateRandom() {
let number1 = Math.floor(Math.random() * 100) + 1;
let number2 = Math.floor(Math.random() * 100) + 1;
while (number1 !== number2) {
document.getElementById('num').innerHTML += /*HTML*/ `${number1} != ${number2}<br>`;
number1 = Math.floor(Math.random() * 100) + 1
number2 = Math.floor(Math.random() * 100) + 1
}
document.getElementById('display').innerHTML = 'Equal numbers found ' + number1 + ' ' + number2 ;
}
</script>
</body>
</html>

View file

@ -0,0 +1,27 @@
<!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 id="app">
<button onclick="updateview()">Print nummer</button>
</div>
<script>
function updateview() {
for (let i = 1; i < 21; i++) {
if (i % 2 == 0){
document.getElementById('app').innerHTML += /*HTML*/ `
<ul>${i}</ul>
`;
}
}
}
</script>
</body>
</html>

33
oppgaver/uke5/revers.html Normal file
View file

@ -0,0 +1,33 @@
<!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 id="app">
<input onchange="getText()" type="text" id="fromUser">
<div id="inputText">Fra Bruker</div>
<div id="reverseText">Reversert</div>
</div>
<script>
var inputText;
function getText() {
inputText = document.getElementById('fromUser').value;
document.getElementById('inputText').innerHTML = inputText;
reverseText(inputText);
}
function reverseText(textToReverse) {
document.getElementById('reverseText').innerHTML = ' ';
for (i = textToReverse.length; i >= 0; i--) {
document.getElementById('reverseText').innerHTML += textToReverse.charAt(i);
}
}
</script>
</body>
</html>

View file

@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Finn vokaler</title>
</head>
<body>
<button onclick="compareLetters('Dette er en test æøå')">Finn vokaler</button>
<div id="letters">inputString</div>
<div id="vokaler">vokaler</div>
<script>
function compareLetters(inputString) {
let vovels = 0;
var theChar;
document.getElementById('letters').innerHTML = inputString;
var charList = ['a', 'e', 'i', 'u', 'o', 'æ', 'ø', 'å'];
for (let i = 0; i <= inputString.length; i++) {
theChar = inputString.charAt(i);
if (charList.indexOf(theChar) != -1) {
vovels++
}
}
document.getElementById('vokaler').innerHTML = `${vovels}`;
}
</script>
</body>
</html>