lyspære conditionals
This commit is contained in:
parent
fc7f07ef47
commit
49cf225a2e
985
oppgaver/bulb.png
Normal file
985
oppgaver/bulb.png
Normal file
File diff suppressed because one or more lines are too long
|
@ -1,94 +1,44 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>If else else if</title>
|
<title>If else else if</title>
|
||||||
<style>
|
<style>
|
||||||
.hungrySetting{
|
.lightBulb {
|
||||||
height: 20px;
|
height: 200px;
|
||||||
width: 200px;
|
width: 200px;
|
||||||
background-color: lightgray;
|
background-color: grey;
|
||||||
cursor: pointer;
|
}
|
||||||
|
|
||||||
|
img {
|
||||||
|
border-radius: 180px;
|
||||||
|
border-radius: 50%;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="result" id="resultBox">Result: </div>
|
<div class="lightBulb" id="bulb">
|
||||||
<div class="hungrySetting" onclick="changeHungrySetting()">Change hungry Status: </div>
|
</div>
|
||||||
<div id="hungryText">I'm hungry</div>
|
<button onclick="onOff()">Av/På</button>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
let hungry = true;
|
let on = false;
|
||||||
function changeHungrySetting(){
|
function onOff() {
|
||||||
hungry = !hungry;
|
if (on != true) {
|
||||||
changeHungryText();
|
document.getElementById('bulb').style.backgroundColor = 'yellow';
|
||||||
|
document.getElementById('bulb').innerHTML = /*HTML*/ `
|
||||||
|
<img src="https://getacademy.moodlecloud.com/pluginfile.php/5208/mod_label/intro/bulb.png">
|
||||||
|
`
|
||||||
|
on = true;
|
||||||
|
} else {
|
||||||
|
document.getElementById('bulb').style.backgroundColor = 'grey';
|
||||||
|
document.getElementById('bulb').innerHTML = '';
|
||||||
|
on = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
function changeHungryText(){
|
|
||||||
if (hungry == true){
|
|
||||||
document.getElementById('hungryText').innerHTML = 'I`m hungry'
|
|
||||||
} else {
|
|
||||||
document.getElementById('hungryText').innerHTML = 'I`m not hungry'
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let numberOne = 5;
|
|
||||||
let numberTwo = 23;
|
|
||||||
|
|
||||||
let textNumber = "30";
|
|
||||||
|
|
||||||
check()
|
|
||||||
function check(){
|
|
||||||
OrCheck();
|
|
||||||
};
|
|
||||||
function setTextToTrue() {
|
|
||||||
document.getElementById('resultBox').innerHTML += true;
|
|
||||||
}
|
|
||||||
function setTextToFalse() {
|
|
||||||
document.getElementById('resultBox').innerHTML += false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function NotEqualTo() {
|
|
||||||
if (numberOne != numberTwo){
|
|
||||||
setTextToTrue();
|
|
||||||
} else {
|
|
||||||
setTextToFalse();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
function EqualTo(){
|
|
||||||
if (numberTwo == textNumber){
|
|
||||||
setTextToTrue();
|
|
||||||
} else {
|
|
||||||
setTextToFalse();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
function LessThan(){
|
|
||||||
if (numberOne < numberTwo){
|
|
||||||
setTextToTrue();
|
|
||||||
} else {
|
|
||||||
setTextToFalse();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
function LargerThan(){
|
|
||||||
if (numberOne > numberTwo){
|
|
||||||
setTextToTrue();
|
|
||||||
} else {
|
|
||||||
setTextToFalse();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
function AndCheck(){
|
|
||||||
if (numberOne < 20 && numberTwo > numberOne){
|
|
||||||
setTextToTrue();
|
|
||||||
} else {
|
|
||||||
setTextToFalse();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
function OrCheck(){
|
|
||||||
if (numberOne > 50 || numberTwo > numberOne){
|
|
||||||
setTextToTrue();
|
|
||||||
} else {
|
|
||||||
setTextToFalse();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
Loading…
Reference in a new issue