74 lines
2.3 KiB
HTML
74 lines
2.3 KiB
HTML
|
<!doctype html>
|
||
|
<html>
|
||
|
<head>
|
||
|
<title>Opptaksoppgave</title>
|
||
|
<style>
|
||
|
div {
|
||
|
color: blue;
|
||
|
background-color: lightblue;
|
||
|
padding: 10px;
|
||
|
margin: 10px;
|
||
|
border: solid green 2px;
|
||
|
width: 30px;
|
||
|
height: 30x;
|
||
|
float: left;
|
||
|
}
|
||
|
div.førstPåLinja {
|
||
|
clear: left;
|
||
|
}
|
||
|
</style>
|
||
|
|
||
|
</head>
|
||
|
<div id="r1k1" onclick="trykk(this, 'r1k2','r2k1', 'r2k1', 'r2k1')">7</div>
|
||
|
<div id="r1k2" onclick="trykk(this, 'r1k1','r1k3', 'r2k2', 'r2k2')">1</div>
|
||
|
<div id="r1k3" onclick="trykk(this, 'r1k2','r2k3', 'r2k3', 'r2k3')">2</div>
|
||
|
|
||
|
<div id="r2k1" class="førstPåLinja" onclick="trykk(this, 'r2k2','r1k1', 'r3k1', 'r3k1')">5</div>
|
||
|
<div id="r2k2" onclick="trykk(this, 'r2k1','r1k2', 'r2k3', 'r3k2')"></div>
|
||
|
<div id="r2k3" onclick="trykk(this, 'r2k2','r1k3', 'r3k3', 'r3k3')">3</div>
|
||
|
|
||
|
<div id="r3k1" class="førstPåLinja" onclick="trykk(this, 'r2k1','r3k2', 'r3k2', 'r3k2')">8</div>
|
||
|
<div id="r3k2" onclick="trykk(this, 'r3k1','r2k2', 'r3k3', 'r3k3')">4</div>
|
||
|
<div id="r3k3" onclick="trykk(this, 'r3k2','r2k3', 'r2k3', 'r2k3')">6</div>
|
||
|
|
||
|
<button id="riktig" onclick="test(this)">sjekk her</button>
|
||
|
|
||
|
<script>
|
||
|
function trykk(tagElement, alt1, alt2, alt3, alt4) {
|
||
|
if(document.getElementById(alt1).innerHTML == '') {
|
||
|
document.getElementById(alt1).innerHTML = tagElement.innerHTML;
|
||
|
tagElement.innerHTML = '';
|
||
|
}
|
||
|
if(document.getElementById(alt2).innerHTML == '') {
|
||
|
document.getElementById(alt2).innerHTML = tagElement.innerHTML;
|
||
|
tagElement.innerHTML = '';
|
||
|
}
|
||
|
if(document.getElementById(alt3).innerHTML == '') {
|
||
|
document.getElementById(alt3).innerHTML = tagElement.innerHTML;
|
||
|
tagElement.innerHTML = '';
|
||
|
}
|
||
|
if(document.getElementById(alt4).innerHTML == '') {
|
||
|
document.getElementById(alt4).innerHTML = tagElement.innerHTML;
|
||
|
tagElement.innerHTML = '';
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
function test() {
|
||
|
var array = ['r1k1', 'r1k2', 'r1k3', 'r2k1', 'r2k2', 'r2k3', 'r3k1', 'r3k2', 'r3k3'].map(id => document.getElementById(id).innerHTML);
|
||
|
let svar = [1,2,3,4,5,6,7,8,''];
|
||
|
if (array.toString() == svar.toString()) {
|
||
|
alert('Hurra!!');
|
||
|
}
|
||
|
else {
|
||
|
alert('Sjekk consolen')
|
||
|
console.log(array === svar);
|
||
|
console.log(array);
|
||
|
console.log(svar);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
</script>
|
||
|
</body>
|
||
|
</html>
|