Skip to content

Instantly share code, notes, and snippets.

@outoftime
Forked from courtney-scripted/index.html
Last active February 6, 2018 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save outoftime/005b0390d68f9d0f0ec5392cd0772cc9 to your computer and use it in GitHub Desktop.
Save outoftime/005b0390d68f9d0f0ec5392cd0772cc9 to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=005b0390d68f9d0f0ec5392cd0772cc9
<!DOCTYPE html>
<html>
<head>
<title>09.1 Basic Conditionals Automatic Test Grader</title>
</head>
<body>
<h1> Second Grade End of Year Test </h1>
<h3> English Language Arts </h3>
<p> What is the abbreviation for Monday? </p>
<input id="english" placeholder="your answer">
<button id="englishButton"> Submit </button>
<p id="englishResult"></p>
<h3> Math </h3>
<p> What is 10 + 10 + 10? </p>
<input id="math" placeholder="your answer">
<button id="mathButton"> Submit </button>
<p id="mathResult"></p>
<h3> Social Studies </h3>
<p> What is the capital of New York? </p>
<input id="socialStudies" placeholder="your answer">
<button id="socialStudiesButton"> Submit </button>
<p id="socialStudiesResult"></p>
<h3> Science </h3>
<p> Is ice a solid, liquid, or gas? </p>
<input id="science" placeholder="your answer">
<button id="scienceButton"> Submit </button>
<p id="scienceResult"></p>
</body>
</html>

Multi-Subject Quiz

Make the multi-subject quiz work correctly!

  1. Change the ? in the if/else statement for the English question so that it checks for the correct answer, which is Mon
  2. Add an if/else statement for the Math question so that it prints “Correct!” if the answer is 30, and “Wrong! Try again” otherwise.
  3. Add an if/else statement for the Social Studies question so that it prints “Correct!” if the answer is Albany, and “Wrong! Try again” otherwise.
  4. Add a click handler with an if / else statement for the Science question so that it checks for the answer solid.

If you finish early…

Make it so that each question turns green if you get it right, and red if you get it wrong.

You’ll notice that your four click handlers all contain pretty similar code. Write a function called checkAnswer() that is given the correct answer, along with selectors for the relevant <div>s, and does the right thing for all four questions.

{"enabledLibraries":["jquery"],"hiddenUIComponents":["editor.css"]}
$("#englishButton").click(function(){
var answer = $("#english").val();
if (answer === "?") {
$("#englishResult").text("Correct!");
} else {
$("#englishResult").text("Wrong! Try again.");
}
});
$("#mathButton").click(function(){
var answer = $("#math").val();
$("#mathResult").text("Correct!");
});
$("#socialStudiesButton").click(function(){
var answer = $("#socialStudies").val();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment