Skip to content

Instantly share code, notes, and snippets.

@asathoor
Last active February 21, 2017 10:55
Show Gist options
  • Save asathoor/c5342ffce5764fd9b4d6430020049364 to your computer and use it in GitHub Desktop.
Save asathoor/c5342ffce5764fd9b4d6430020049364 to your computer and use it in GitHub Desktop.
dom03.html
<!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>
@asathoor
Copy link
Author

Important: the code will look for two images billede.jpeg and enterprise.png in the project root folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment