liten bug med operatorene

This commit is contained in:
Geir Okkenhaug Jerstad 2024-08-23 13:46:21 +02:00
parent 7b19e5860c
commit b5a58f8cc6

View file

@ -1,23 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Krokodille</title>
<style>
img{
img {
height: 100px;
}
div{
div {
background-color: gray;
}
</style>
</head>
<body>
<div>
Poeng: <div id="points"></div>
<img src="../../Crocodile.svg.png">
<div>Lovlige operatorer < og > og = og ==</div>
<div>Lovlige operatorer '<' og '>' og '=' og '==' </div>
<div id="number1">
</div>
@ -35,25 +38,28 @@
var number1
var number2
document.getElementById('points').innerHTML = `${points}`;
function randomNumber(){
function randomNumber() {
number1 = Math.floor(Math.random() * 10) + 1;
number2 = Math.floor(Math.random() * 10) + 1;
document.getElementById('number1').innerHTML = `${number1}`;
document.getElementById('number2').innerHTML = `${number2}`;
}
function check(){
function check() {
let operator = document.getElementById("operator").value;
// console.log(eval(number1 + operator + number2))
if (operator = '='){
operator = '==';
console.log(operator)
if (operator == '=') {
operator == '==';
}
if (eval(number1 + operator + number2)){
console.log(eval(number1 + operator + number2));
if (eval(number1 + operator + number2)) {
++points;
document.getElementById('points').innerHTML = `${points}`;
} else {
alert('It is Wrong! to use Alert');
console.log(operator)
}
}
</script>
</body>
</html>