ASDV-WebDev/Semester 1/Assignments/JavaScript/ch03/carla/carla_adding.html

330 lines
8.2 KiB
HTML
Raw Normal View History

2023-03-14 09:48:18 -05:00
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Carla's Classroom | It All Adds Up</title>
<link href="carla.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function addIt()
{
var num1a = 0;
var num1b = 0;
var sum1 = 0;
var count1 = 0;
var response = " ";
var result = " ";
levelOne();
function levelOne()
{
//problem 1
var num1a = (Math.floor(Math.random() * 10)) + 1;
var num1b = (Math.floor(Math.random() * 10)) + 1;
var sum1 = num1a + num1b;
var response = parseInt(prompt("What is the sum of " + num1a + " and " + num1b + " ?"));
if (response == sum1)
{
count1 = count1 + 1;
result = "correct!";
alert(result);
}
else
{
result = "incorrect";
alert(result);
}
if (count1 == 3)
{
levelTwo();
return;
}
//problem 2
var num1a = (Math.floor(Math.random() * 10)) + 1;
var num1b = (Math.floor(Math.random() * 10)) + 1;
var sum1 = num1a + num1b;
var response = parseInt(prompt("What is the sum of " + num1a + " and " + num1b + " ?"));
if (response == sum1)
{
count1 = count1 + 1;
result = "correct!";
alert(result);
}
else
{
result = "incorrect";
alert(result);
}
if (count1 == 3)
{
levelTwo();
return;
}
//problem 3
var num1a = (Math.floor(Math.random() * 10)) + 1;
var num1b = (Math.floor(Math.random() * 10)) + 1;
var sum1 = num1a + num1b;
var response = parseInt(prompt("What is the sum of " + num1a + " and " + num1b + " ?"));
if (response == sum1)
{
count1 = count1 + 1;
result = "correct!";
alert(result);
}
else
{
result = "incorrect";
alert(result);
}
if (count1 == 3)
{
levelTwo();
return;
}
//problem 4
var num1a = (Math.floor(Math.random() * 10)) + 1;
var num1b = (Math.floor(Math.random() * 10)) + 1;
var sum1 = num1a + num1b;
var response = parseInt(prompt("What is the sum of " + num1a + " and " + num1b + " ?"));
if (response == sum1)
{
count1 = count1 + 1;
result = "correct!";
alert(result);
}
else
{
result = "incorrect";
alert(result);
}
if (count1 == 3)
{
levelTwo();
return;
}
else
{
alert("You need more practice at this level.");
return;
}
}
function levelTwo()
{
var count2 = 0;
alert("You're at Level Two");
//problem 1
var num2a = (Math.floor(Math.random() * 100)) + 1;
var num2b = (Math.floor(Math.random() * 100)) + 1;
var sum2 = num2a + num2b;
var response = parseInt(prompt("What is the sum of " + num2a + " and " + num2b + " ?"));
if (response == sum2)
{
count2 = count2 + 1;
result = "correct!";
alert(result);
}
else
{
result = "incorrect";
alert(result);
}
if (count2 == 3)
{
levelThree();
return;
}
//problem 2
var num2a = (Math.floor(Math.random() * 100)) + 1;
var num2b = (Math.floor(Math.random() * 100)) + 1;
var sum2 = num2a + num2b;
var response = parseInt(prompt("What is the sum of " + num2a + " and " + num2b + " ?"));
if (response == sum2)
{
count2 = count2 + 1;
result = "correct!";
alert(result);
}
else
{
result = "incorrect";
alert(result);
}
if (count2 == 3)
{
levelThree();
return;
}
//problem 3
var num2a = (Math.floor(Math.random() * 100)) + 1;
var num2b = (Math.floor(Math.random() * 100)) + 1;
var sum2 = num2a + num2b;
var response = parseInt(prompt("What is the sum of " + num2a + " and " + num2b + " ?"));
if (response == sum2)
{
count2 = count2 + 1;
result = "correct!";
alert(result);
}
else
{
result = "incorrect";
alert(result);
}
if (count2 == 3)
{
levelThree();
return;
}
//problem 4
var num2a = (Math.floor(Math.random() * 100)) + 1;
var num2b = (Math.floor(Math.random() * 100)) + 1;
var sum2 = num2a + num2b;
var response = parseInt(prompt("What is the sum of " + num2a + " and " + num2b + " ?"));
if (response == sum2)
{
count2 = count2 + 1;
result = "correct!";
alert(result);
}
else
{
result = "incorrect";
alert(result);
}
if (count2 == 3)
{
levelThree();
return;
}
else
{
alert("You need more practice at this level.");
return;
}
}
function levelThree()
{
var count3 = 0;
alert("You're at Level Three");
//problem 1
var num3a = (Math.floor(Math.random() * 100)) + 1;
var num3b = (Math.floor(Math.random() * 100)) + 1;
var num3c = (Math.floor(Math.random() * 100)) + 1;
var sum3 = num3a + num3b + num3c;
var response = parseInt(prompt("What is the sum of " + num3a + ", " + num3b + ", and " + num3c + " ?"));
if (response == sum3)
{
count3 = count3 + 1;
result = "correct!";
alert(result);
}
else
{
result = "incorrect";
alert(result);
}
if (count3 == 3)
{
alert("That's all, folks! Proceed to multiplication now!");
return;
}
//problem 2
var num3a = (Math.floor(Math.random() * 100)) + 1;
var num3b = (Math.floor(Math.random() * 100)) + 1;
var num3c = (Math.floor(Math.random() * 100)) + 1;
var sum3 = num3a + num3b + num3c;
var response = parseInt(prompt("What is the sum of " + num3a + ", " + num3b + ", and " + num3c + " ?"));
if (response == sum3)
{
count3 = count3 + 1;
result = "correct!";
alert(result);
}
else
{
result = "incorrect";
alert(result);
}
if (count3 == 3)
{
alert("That's all, folks! Proceed to multiplication now!");
return;
}
//problem 3
var num3a = (Math.floor(Math.random() * 100)) + 1;
var num3b = (Math.floor(Math.random() * 100)) + 1;
var num3c = (Math.floor(Math.random() * 100)) + 1;
var sum3 = num3a + num3b + num3c;
var response = parseInt(prompt("What is the sum of " + num3a + ", " + num3b + ", and " + num3c + " ?"));
if (response == sum3)
{
count3 = count3 + 1;
result = "correct!";
alert(result);
}
else
{
result = "incorrect";
alert(result);
}
if (count3 == 3)
{
alert("That's all, folks! Proceed to multiplication now!");
return;
}
//problem 4
var num3a = (Math.floor(Math.random() * 100)) + 1;
var num3b = (Math.floor(Math.random() * 100)) + 1;
var num3c = (Math.floor(Math.random() * 100)) + 1;
var sum3 = num3a + num3b + num3c;
var response = parseInt(prompt("What is the sum of " + num3a + ", " + num3b + ", and " + num3c + " ?"));
if (response == sum3)
{
count3 = count3 + 1;
result = "correct!";
alert(result);
}
else
{
result = "incorrect";
alert(result);
}
if (count3 == 3)
{
alert("That's all, folks! Proceed to multiplication now!");
return;
}
else
{
alert("That's all, folks! But you need more practice at this level.");
return;
}
}
}
</script>
</head>
<body>
<div id="container">
<img src="images/arith_big.jpg" class="floatleft" />
<h1 id="logo">It All Adds Up!</h1>
<div style="clear:both;"></div>
<div align="left">
<blockquote>
<p><a href="index.html"><img src="images/owl_button.jpg" width="50" height="50" />Home</a>
<a href="carla.html"><img src="images/carla_button.jpg" width="50" height="65" />Meet Carla </a>
<a href="reading.html"><img src="images/read_button.jpg" />Reading</a>
<a href="writing.html"><img src="images/write_button.jpg" width="50" height="50" />Writing</a>
<a href="math.html"><img src="images/arith_button.jpg" />Arithmetic</a>
<br /></p></blockquote> </div>
<div id="content">
<p>This arithmetic test will increase in difficulty as you prove you are ready for harder problems.
As soon as you get 3 problems correct in Level One, you will progress to Level Two and then to Level Three.</p>
<p><input type="button" onclick="addIt()" value="begin the test" /> </p>
</div>
</div>
<div id="footer"> <h3>*Carla's Motto: Never miss a chance to teach -- and to learn!</h3>
</div>
</body>
</html>