1
mirror of https://github.com/jakejarvis/my-first-website.git synced 2025-04-26 06:35:22 -04:00

148 lines
3.2 KiB
HTML

<html>
<head>
<title>Math Test!</title>
<!-- Original: Anja Henseler -->
<!-- Web Site: http://www.hens.com/binoculars -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin -->
<SCRIPT LANGUAGE="JavaScript">
correct=0;
wrong=0;
function random(maxValue) {
day= new Date();
hour= day.getHours();
min=day.getMinutes();
sec=day.getSeconds();
mili=day.getTime()
return(((hour*3600)+(min*60)+(sec)+mili) % maxValue);
}
function ranom(maxValue) {
day= new Date();
mil=day.getTime();
return((mil) % maxValue);
}
function add() {
if(document.quizform.arithmetic[0].checked)
maxValue=10;
else {
if(document.quizform.arithmetic[1].checked)
maxValue=30;
else {
maxValue=60;
}
}
numA=random(maxValue);
numB=ranom(maxValue);
numC=numA + numB;
Answer=window.prompt( numA + "+" + numB + " = ", "");
ans();
}
function subtract() {
if(document.quizform.arithmetic[0].checked)
maxValue=10;
else
{if(document.quizform.arithmetic[1].checked)
maxValue=30;
else {
maxValue=60
}
}
numA=random(maxValue);
numB=ranom(maxValue);
numC=numA - numB;
Answer=window.prompt( numA + "-" + numB+ " = ", 0);
ans()
}
function divide() {
if(document.quizform.arithmetic[0].checked)
maxValue=10;
else {
if(document.quizform.arithmetic[1].checked)
maxValue=30;
else {
maxValue=60
}
}
numA=random(maxValue)+1;
numB=ranom(maxValue)+1;
numC=numA / numB;
numC=Math.round(numC)
window.alert("Please round your answer off:\n"
+".5 or higher rounds one number up\n"
+".4 or lower rounds one number down");
Answer=window.prompt( numA + "/" + numB + " = ", 0);
ans()
}
function multiply() {
if(document.quizform.arithmetic[0].checked)
maxValue=10;
else {
if(document.quizform.arithmetic[1].checked)
maxValue=30;
else {
maxValue=60
}
}
numA=random(maxValue);
numB=ranom(maxValue);
numC=numA * numB;
Answer=window.prompt( numA + "*" + numB + " = ", 0);
ans();
}
function check() {
if ((correct+wrong) != 0) {
score = "" + ((correct / (correct + wrong)) * 100);
score = score.substring(0,4) + "%";
alert("YOUR SCORE: " + score + "\n"
+ correct + " correct\n"
+ wrong + " incorrect")
}
else alert("You have not completed any exercises yet.");
}
function ans() {
if (Answer == numC) {
correct++;
msg = "Congratulations, your answer is correct.";
}
else {
wrong++;
msg = "Oops! " + Answer + " is incorrect.\n\n"
+ "The correct answer was " +numC + ".";
}
score = "" + ((correct / (correct + wrong)) * 100);
score = score.substring(0,4) + "%";
alert(msg + "\n\nYOUR SCORE: " + score + "\n"
+ correct + " correct\n"
+ wrong + " incorrect")
}
</script>
<!-- End -->
</head>
<body bgcolor="Cornsilk">
<center><h1>Math Test!</h1><br><hr><br>
<center>
<form name=quizform>
<input type=button value="add" onClick="add()">
<input type=button value="subtract" onClick="subtract()">
<input type=button value="multiply" onClick="multiply()">
<input type=button value="divide" onClick="divide()">
<br>
<br>
<input type="radio" name="arithmetic">Easy
<input type="radio" name="arithmetic" checked>Moderate
<input type="radio" name="arithmetic">Difficult
<br>
<br>
<input type=button value="Check Score" onClick="check()">
<input type=button value="Reset Score" onClick="javascript:correct=0;wrong=0;">
</form>
</center>
</body>
</html>