javascript - How do i show if an answer is correct or not -


I'm trying to make a big "you'r right!" On the image of a cat / dog but I do not know how I am guessing that to create a function in Javascript, I know that any answer is correct or not?

Codeple link:

  var question = [['http://i.imgur.com/xKE07.jpg', '1 '], [' http://images6.fanpop.com/image/photos/32900000/Cat-cats-32958715-1440-900.jpg ',' 1 '], [' http://tippvet.com/wp -content / uploads / 2013/05 / cat-vet.jpg ',' 1 '], [' http://www.bubblews.com/assets/images/news/1825371279_1382541931.jpg ',' 1 '], [ 'http://stylonica.com/wp-content/uploads/2014/03/Cute-Dog-Walpaper.jpg', '0'], ['http://upload.wikimedia.org/wikipedia/commons/2 /26/YellowLabradorLooking_new.jpg ',' 0 '], [' http://thestylishdog.com/wp-content/uploads/2009/07/cute-dog2.jpg ',' 0 '], [' http: / /w8themes.com/wp-content/uploads/2013/09/Dog-Computer-Wallpaper.jpg ',' 0 ']]; var qNo = 0; Var correct = 0; Var cnt = 0; The next question (feedback) of the function {if ((qNo & lt; questions.length) & amp; (feedback == question [qNo] [1])) {right ++; } Document.getElementById ('urscore'). Style.display = "block" document.getElementById ('score'). InnerHTML = 'You have' ++ (+++) + + (CNT + 1) + right '; QNo ++; If (qNo & lt; questions.length) {document.getElementById ('img'). Src = Question [qNo] [0]; Cnt ++; }} Onload = function () {document.getElementById ('img'). Src = Question [0] [0]; }   

HTML

  & lt; Div id = "header" & gt; & Lt; H1 & gt; Cat or a dog? & Lt; / H1> & Lt; / Div & gt; & Lt; Img height = "250" id = "img" & gt; & Lt; Div id = "wrapper" & gt; & Lt; button class = "left" onclick = "next question ('0')" & gt; He's a dog! & Lt; / Button & gt; & Lt; Button class = "right" onclick = "next question ('1')" & gt; This is a cat! & Lt; / Button & gt; & Lt; Br> & Lt; Br> & Lt; Br> & Lt; Br> & Lt; Br> & Lt; Br> & Lt; Div id = "urscore" & gt; This is your score & lt; / Div & gt; & Lt; div id = "score" & gt; & Lt; / Div & gt; & Lt; Div id = "result" & gt; & Lt; / Div & gt;    

This works - you want to use the timeout to show the text

  function Next question (feedback) {var ovl = document.getElementById ("overlay"); Ovl.innerHTML = Feedback == Question [qNo] [1]? "You are right": "no"; If ((qNo & lt; questions.length) & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; responses == question [qNo] [1])) {right ++; } Ovl.style.display = ""; Document.getElementById ('urscore'). Style.display = "block" document.getElementById ('score'). InnerHTML = 'you have' + right + '+ (CNT + 1) +'; qNo ++; If (qNo & lt; questions.length) {document.getElementById ('img'). Onload = function () {ovl.style.display = "none"} document.getElementById ('img'). Src = Question [qNo] [0]; Cnt ++; }} Window.onload = function () {document.getElementById ('img'). Src = Question [0] [0]; }    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -