Just learning a little bit of JavaScript today. Here is a simple little quiz script i wrote for anyone who wants to have a little fun. Enjoy.
<script>
var num_correct = 0; // correct answers
var good = 'Awesome! Thats correct!';
var bad = 'Sorry, that is incorrect! :( ';
// question 1 answer prompt
var user_ans = prompt('Question 1: How many States are in the US? ');
if(user_ans = 52){
num_correct += 1;
alert(good);
}else{
alert(bad);
}
// question 2 answer prompt
user_ans = prompt('Question 2: What color is healty grass? ');
if(user_ans.toLowerCase() === 'green'){
num_correct += 1;
alert(good);
}else{
alert(bad);
}
// question 3 answer prompt
user_ans = prompt('Question 3: What country is the Brand "Sony" from? ');
if(user_ans.toLowerCase() === 'japan'){
num_correct += 1;
alert(good);
}else{
alert(bad);
}
// question 4 answer prompt
user_ans = prompt('Question 4: Question What color is rgb(255,000,000)? ');
if(user_ans.toLowerCase() === 'red'){
num_correct += 1;
alert(good);
}else{
alert(bad);
}
// question 5 answer prompt
user_ans = prompt('Final Question: Name a famous/popular programming code that is 4 letters long and starts with a J : ');
if(user_ans.toLowerCase() === 'java'){
num_correct += 1;
alert(good);
}else{
alert(bad);
}
// Issue prizes below
if(num_correct == 5) { // Gold 5 correct
alert('Congrats!! You answered 5 questions correctly! YOU GET THE GOLD CROWN!' );
}
else if(num_correct >= 3){ // silver 3-4 correct
alert('Hey! Not to bad! Because of your valiant efforts answering '+ num_correct + ' questions correctly, you have won a silver crown. Good job! ');
}
else if(num_correct >= 1){ // bonze 1-2 correct
alert('I must say....not your best. You only answered ' + num_correct + ' question correctly. What the heck, here is a BRONZE crown. Better luck next time.');
}
else{ // no crown..sorry 0 correct
alert('Hmmm....how did you even get your computer to work? You did not answer 1 question correctly. Next time, study up, and try a little bit harder. Best of luck! ');
}
</script>
No comments:
Post a Comment