Skip to content

Instantly share code, notes, and snippets.

@samueljoli
Last active March 16, 2018 11:39
Show Gist options
  • Save samueljoli/98bb0c9f9070659ec820d86574652dad to your computer and use it in GitHub Desktop.
Save samueljoli/98bb0c9f9070659ec820d86574652dad to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=98bb0c9f9070659ec820d86574652dad
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>Trivia!!</h1>
<div id='questions'>
<p id='question'></p>
<p id='result'></p>
</div>
<button id='yes'>Yes</button>
<button id='no'>No</button>
<button id='next'>Next</button>
</body>
</html>

Trivia Trivia!!

{"enabledLibraries":["jquery"],"hiddenUIComponents":["editor.css","editor.html","console","editor.javascript"]}
var questionOne = 'Goku is the GOAT';
var answerOne = 'Yes';
var questionTwo = 'Yamcha is the GOAT';
var answerTwo = 'No';
var questions = [
questionOne,
questionTwo
];
var answers = [
answerOne,
answerTwo
];
var index = 0;
$('#question').text(questions[index]);
$('#yes').click(function(){
var response = $(this).text();
var answer = answers[index];
if(response === answer) {
$('#result').text('Correct');
}
else {
$('#result').text('Wrong');
}
});
$('#no').click(function(){
var response = $(this).text();
var answer = answers[index];
console.log(response, answer);
if(response === answer) {
$('#result').text('Correct');
}
else {
$('#result').text('Wrong');
}
});
$('#next').click(function(){
++index;
$('#result').text('');
$('#question').text(questions[index]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment