Last active
February 21, 2017 10:55
-
-
Save asathoor/c5342ffce5764fd9b4d6430020049364 to your computer and use it in GitHub Desktop.
dom03.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<style> | |
img { | |
width: 100px; | |
height: auto; | |
} | |
</style> | |
</head> | |
<body> | |
<h1> Show a question </h1> | |
<!-- her vises tingene --> | |
<div id="question"></div> | |
<div id="score"></div> | |
<script> | |
/** | |
* Create radios | |
*/ | |
function showQuestion( what, id, name, value ){ | |
// skriver knappen | |
this.vis = document.getElementById( 'question' ); | |
this.vis.innerHTML += '<input id="btn' | |
+ id | |
+ '" type="radio" name="' | |
+ name | |
+ '" value="' | |
+ value | |
+ '" id="myRadio">' | |
+ what | |
+ '<br>'; | |
}; | |
function billede( fil, alt ){ | |
this.img = document.getElementById( 'score' ); | |
this.img.innerHTML += '<img src="' + fil + '" alt="' + alt + '">'; | |
} | |
meier = new billede( 'billede.jpeg', 'Her er min alt tekst lissom' ); | |
enterprise = new billede( 'enterprise.jpg', 'Her er min alt tekst lissom' ); | |
// radios | |
fiat = new showQuestion( 'Fiat', 1, 'cars', 10 ); | |
porche = new showQuestion( 'Porche', 2, 'cars', 200 ); | |
reneault = new showQuestion( 'Renault', 3, 'cars', 200 ); | |
// SCORE | |
var hiScore = 0; | |
document.getElementById('btn1').addEventListener('click', | |
function(){ | |
console.log('Klik på btn1') ; | |
hiScore = hiScore + 245252555; | |
console.log('Jubii, hvor er du dygtig. Point: ' + hiScore ); | |
this.scoreTag = document.getElementById( 'score' ); | |
this.scoreTag.innerHTML = 'Hurra! ' + hiScore; | |
// question blank | |
this.scoreTag = document.getElementById( 'question' ); | |
this.scoreTag.innerHTML = ''; | |
}, | |
false); | |
document.getElementById('btn2').addEventListener('click', function(){ console.log('Klik på btn2') }, false); | |
if ( document.getElementById('btn3').addEventListener('click', function(){ | |
console.log('Klik på btn3'); | |
var tom = document.getElementById( 'question' ); | |
tom.innerHTML = '.. next ..'; | |
}, false) ){ | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Important: the code will look for two images
billede.jpeg
andenterprise.png
in the project root folder.