<!DOCTYPE html>
<html>
<head>
<title>
</title>
<script>
function getInputAsText(_id){return document.getElementById(_id).value};
function getInputAsNumber(_id){return parseFloat(document.getElementById(_id).value)};
function setOutput(_id, _value){document.getElementById(_id).value = _value;}//Is it NULL? If it is, why and how to fix?
function calculate()
{
// declare a variable
var score;
var myAnswer1;
var myAnswer2;
var myAnswer3;
var myResult1;
var myResult2;
var myResult3;
// get variable's value
score = 0;
// perform this
if (myAnswer1 == "8")
{
score = score + 1 ;// got this one right
myResult1 = "Correct";
}
else
{
myResult1 = "WRONG! It's 8";
}
if (myAnswer2 == "Apple")
{
score = score + 1 ;// got this one right
myResult2 = "Correct";
}
else
{
myResult2 = "WRONG! It's Apple"
}
if (myAnswer3== "Microsoft")
{
score = score + 1 ;// got this one right
myResult3 = "Correct";
}
else
{
myResult3 = "WRONG! It's Microsoft"
}
// write Output value
setOutput("myResult1", myResult1);
setOutput("myResult2", myResult2);
setOutput("myResult3", myResult3);
setOutput("score", "Your score is " + score + " out of 3 ");
}
</script>
</head>
<body>
Instruction:<br>
Answer the three questions and press go.<br>
Your score will appear.<br>
<br>
Input Values:<br>
1. A byte is how many bits? <input id="myAnswer1"><br>
2. Steve Jobs heads what company? <input id="myAnswer2"><br>
3. Bill Gates heads what company? <input id="myAnswer3"><br>
<button onclick="calculate()">Go</button><br>
<br>
Output value:<br>
Result #1: <input type="text" id = myResult1" size="70"><br>
Result #2: <input id="myResult2" size="70"><br>
Result #3: <input id="myResult3" size="70"><br>
Your Score: <input type="text" id = score" size="70"><br>
</body>
</html>