Javascript
Hello learner! Are you new to python? Press 1 if you are, and 2 if you know some. <script> document.addEventListener('keydown', function(event){ if (event.key == '1'){ document.writeln("That's okay! You came to the right place!"); } else if (event.key == '2'){ document.writeln("Well that's good! Let's take a quiz to see how much you know!"); setTimeout(() => { quiz() }, 5536); }; }); var quiz = function() { var variables = 0; document.writeln("Which way would you create a variable called var that holds the interger 13?<br>A.print 'banana banana banana banana' <br>B. var = 13' <br>C. var == 13"); document.addEventListener('keydown', function(event){ if (event.key == 'a'){ variables = 0 } else if (event.key == 'b'){ variables += 1 } else if (event.key =='c'){ variables = 0 }; }); document.close(); document.writeln("How would you create a variable that holds a list with three items?<br>A. a_list = ['item', 5, 4.3]<br>B. a_list == an item, another item, 43 <br>C. a_list == chicken, sheep, cow"); document.addEventListener('keydown', function(event){ if (event.key == 'a'){ variables += 1; } else if (event.key == 'b'){ variables -= 1; } else if (event.key == 'c'){ variables -= 1; }; }); document.close(); documetn.writeln("How would you pick a random item from a list?<br>A.<br>B.import random<br>fruit = ['banana','apple','cherry']") document.addEventListener('keydown', function(event){ if (event.key == 'a'){ variables += 1; } else if (event.key == 'b'){ variables -= 1; } else if (event.key == 'c'){ variables -= 1; }; }); }; </script>
Try running it, what is wrong?
xxpertHacker
Also, you're misusing setTimeout
, it should be:
setTimeout(quiz, 5536);
xxpertHacker
Didn't run it, documetn
doesn't exist
}); document.close(); documetn.writeln("How would you pick a random item from a list?<br>A.<br>B.import random<br>fruit = ['banana','apple','cherry']")
documetn.writeln
->
document.writeln
Also, I'd shame you for using Document#open
, Document#write
, Document#writeln
, Document#close
, or Element#innerHTML
.
Don't touch those, use the proper W3C DOM API.
RYANTADIPARTHI
For one thing, try adding ===
instead of ==
. Also where's the prompt, or something. You can make it an int, and try that.
Kitty6709
Why won’t the event work?? I don’t see anything wrong with it.
problem 1
Typo
problem 2
This is not how js works, this code will never work. First, there is no
document.writeln
, we havedocument.write
, but I doubt that is what you want.Second, JS iS synchronous, so that means this code won't even run in any particular order, its just first come first serve, and finally, you should take a js tutorial
https://www.w3schools.com/js/DEFAULT.asp
document.writeln
in js...Thanks! I read the tutorial, changed my code, and have another question: why isn't this working?
@Coder100