Hallo,
Ik ben bezig met een eindopdracht programmeren en snap niet waarom mijn code niet werkt. Ik heb een simpel spelletje gemaakt die al werkte alleen met .onclick in de html, en dat mocht niet dus heb ik het .onclick nu in mijn JS gezet en nu werkt de code niet meer.. Kan iemand mij helpen??
var vraag1 = {
vraag:"Are you ready to fight Mike Tyson in this bare knuckle fight?",
antwoord1:"Yes",
antwoord2:"No",
reactie1:"wel okay then, goodluck ya sick bastard!.",
reactie2:"Well too bad. He already heard what you said about his mom.. Goodluck smartass" };
var vraag2 = {
vraag:"(Ding Ding!) Okay the match has begun! Mike comes right and you.. You: Lowpunch or Highpunch ",
antwoord1:"lowpunch",
antwoord2:"highpunch",
reactie1:"Good! He didn't see that one coming! His rockhard stomach did hurt your hand though..",
reactie2:"Tyson dodges the blow to the face and returns with a hit to the stomach!" };
var vraag3 = {
vraag:"Mike is laughing because of your pain. Quick! Do you: Uppercut or KICK in de balls ",
antwoord1:"uppercut",
antwoord2:"kick",
reactie1:"Good! the few teeth he had left are now flying threw the air!",
reactie2:"damn! because of the use of steroids he hardly has anything below the belt..." };
var vraag4 = {
vraag:"He's about to throw a punch! Do you: Block or Dodge",
antwoord1:"block",
antwoord2:"dodge",
reactie1:"your tiny arms got crushed bij Tyson's iron fists... ",
reactie2:"your speed was no match for Tyson.. His punch was a full hit! " };
var vraag5 = {
vraag:"Okay tough guy, just stay focust. You're getting your ass kicked. Lets focus on his weeknesses. Do you think you're stronger on a Fysical or Mental level? ",
antwoord1:"fysical",
antwoord2:"mental",
reactie1:"No you dummy! you're stonger on a mental level! But now i'm starting to question your mental strength ",
reactie2:"Yes of course! you're no Einstein, but anyone above the age of 5 can outsmart this dummy" };
var vraag6 = {
vraag:"Mike is ready to attack you again! Do you: HIT him or tell a Riddle? ",
antwoord1:"hit",
antwoord2:"riddle",
reactie1:"Your hit was dodged by Mike and he finishes you with an uppercut! Goodluck on intesive care for the next few months",
reactie2:"'If a tree falls in a forest, and there is nobody there to hear it, does it make a sound?' Tyson's head just exploded!!Congratulations! You defeated Mike Tyson! Enjoy money, power and women for the rest of your life!" };
var vragen = [ vraag1, vraag2, vraag3, vraag4, vraag5, vraag6]; //Deze array code heb ik van Codecademy
var vraagCount = 0; // var vraagCount heb ik aangemaakt om aan te geven hoe ver je bent. Hij staat op 0 aangezien dat vraag 1 is binnen de array.
//Hier heb ik een DOM manipulatie toegepast om toegang te krijgen tot mijn elementen in mij Html. Code van w3Schools
var volgende = document.getElementById("btnVolgende");
volgende.onclick = function(event){
var lblVraag = document.getElementById("vraag");
var btnAntwoord = document.getElementById("btnAntwoord");
var antwoord = document.getElementById("antwoord");
var reactie = document.getElementById("reactie");
reactie.innerHTML = "";
antwoord.value = "";
btnAntwoord.disabled = false;
lblVraag.innerHTML = vraag.vraag;
}
//hier heb ik weer gebruik gemaakt van dom manipulatie voor wanneer de gebruiker zijn eerste antwoord geeft en op antwoord drukt.
var antwoord = document.getElementById("btnAntwoord");
antwoord.onclick = function(event){
var antwoord = document.getElementById("antwoord");
var reactie = document.getElementById("reactie");
var btnAntwoord = document.getElementById("btnAntwoord");
btnAntwoord.disabled = true;
vraagCount++;
//toLowercase heb ik toegepast zodat het niet uitmaakt of de gebruiker wel of geen hoofdletters gebruikt
//De code heb ik van W3Schhools gehaald.
// De switchcode heb ik ook van W3Schools.
switch(antwoord.value.toLowerCase())
{
case vraag.antwoord1.toLowerCase():
reactie.innerHTML = vraag.reactie1;
break;
case vraag.antwoord2.toLowerCase():
reactie.innerHTML = vraag.reactie2;
break;
default:
reactie.innerHTML = "Wrong answer, try again!";
vraagCount--;
btnAntwoord.disabled = false;
antwoord.value = "";
break;
}
}
Ik ben bezig met een eindopdracht programmeren en snap niet waarom mijn code niet werkt. Ik heb een simpel spelletje gemaakt die al werkte alleen met .onclick in de html, en dat mocht niet dus heb ik het .onclick nu in mijn JS gezet en nu werkt de code niet meer.. Kan iemand mij helpen??
var vraag1 = {
vraag:"Are you ready to fight Mike Tyson in this bare knuckle fight?",
antwoord1:"Yes",
antwoord2:"No",
reactie1:"wel okay then, goodluck ya sick bastard!.",
reactie2:"Well too bad. He already heard what you said about his mom.. Goodluck smartass" };
var vraag2 = {
vraag:"(Ding Ding!) Okay the match has begun! Mike comes right and you.. You: Lowpunch or Highpunch ",
antwoord1:"lowpunch",
antwoord2:"highpunch",
reactie1:"Good! He didn't see that one coming! His rockhard stomach did hurt your hand though..",
reactie2:"Tyson dodges the blow to the face and returns with a hit to the stomach!" };
var vraag3 = {
vraag:"Mike is laughing because of your pain. Quick! Do you: Uppercut or KICK in de balls ",
antwoord1:"uppercut",
antwoord2:"kick",
reactie1:"Good! the few teeth he had left are now flying threw the air!",
reactie2:"damn! because of the use of steroids he hardly has anything below the belt..." };
var vraag4 = {
vraag:"He's about to throw a punch! Do you: Block or Dodge",
antwoord1:"block",
antwoord2:"dodge",
reactie1:"your tiny arms got crushed bij Tyson's iron fists... ",
reactie2:"your speed was no match for Tyson.. His punch was a full hit! " };
var vraag5 = {
vraag:"Okay tough guy, just stay focust. You're getting your ass kicked. Lets focus on his weeknesses. Do you think you're stronger on a Fysical or Mental level? ",
antwoord1:"fysical",
antwoord2:"mental",
reactie1:"No you dummy! you're stonger on a mental level! But now i'm starting to question your mental strength ",
reactie2:"Yes of course! you're no Einstein, but anyone above the age of 5 can outsmart this dummy" };
var vraag6 = {
vraag:"Mike is ready to attack you again! Do you: HIT him or tell a Riddle? ",
antwoord1:"hit",
antwoord2:"riddle",
reactie1:"Your hit was dodged by Mike and he finishes you with an uppercut! Goodluck on intesive care for the next few months",
reactie2:"'If a tree falls in a forest, and there is nobody there to hear it, does it make a sound?' Tyson's head just exploded!!Congratulations! You defeated Mike Tyson! Enjoy money, power and women for the rest of your life!" };
var vragen = [ vraag1, vraag2, vraag3, vraag4, vraag5, vraag6]; //Deze array code heb ik van Codecademy
var vraagCount = 0; // var vraagCount heb ik aangemaakt om aan te geven hoe ver je bent. Hij staat op 0 aangezien dat vraag 1 is binnen de array.
//Hier heb ik een DOM manipulatie toegepast om toegang te krijgen tot mijn elementen in mij Html. Code van w3Schools
var volgende = document.getElementById("btnVolgende");
volgende.onclick = function(event){
var lblVraag = document.getElementById("vraag");
var btnAntwoord = document.getElementById("btnAntwoord");
var antwoord = document.getElementById("antwoord");
var reactie = document.getElementById("reactie");
reactie.innerHTML = "";
antwoord.value = "";
btnAntwoord.disabled = false;
lblVraag.innerHTML = vraag.vraag;
}
//hier heb ik weer gebruik gemaakt van dom manipulatie voor wanneer de gebruiker zijn eerste antwoord geeft en op antwoord drukt.
var antwoord = document.getElementById("btnAntwoord");
antwoord.onclick = function(event){
var antwoord = document.getElementById("antwoord");
var reactie = document.getElementById("reactie");
var btnAntwoord = document.getElementById("btnAntwoord");
btnAntwoord.disabled = true;
vraagCount++;
//toLowercase heb ik toegepast zodat het niet uitmaakt of de gebruiker wel of geen hoofdletters gebruikt
//De code heb ik van W3Schhools gehaald.
// De switchcode heb ik ook van W3Schools.
switch(antwoord.value.toLowerCase())
{
case vraag.antwoord1.toLowerCase():
reactie.innerHTML = vraag.reactie1;
break;
case vraag.antwoord2.toLowerCase():
reactie.innerHTML = vraag.reactie2;
break;
default:
reactie.innerHTML = "Wrong answer, try again!";
vraagCount--;
btnAntwoord.disabled = false;
antwoord.value = "";
break;
}
}