Question

In: Computer Science

There are four basic functions in math. They are addition, subtraction, multiplication and division. Children in...

There are four basic functions in math. They are addition, subtraction, multiplication and division. Children in 1st grade focus on addition. They are required to memorize their addition facts from 1 to 12.

Create a function that prompts the user to enter a number between 1 and 12. Then display - using the input supplied - the addition and subtraction math facts for that number from 1 to 12 for the number entered. The output should be the results of the mathematical calculations.

See below example below:

The user enters "5" as their input. Below is the expected output.

Addition Math Facts for "5"

5 + 1 = 6

5 +2 = 7

...

5 + 11 = 16

5 + 12 = 17

Subtraction Math Facts for "5"

12 - 5 =

11 - 5 =

10 - 5 =

...

7 - 5 = 2

6 - 5 = 1

5 - 5 = 0

* Please note the subtraction facts should stop at the input number - the input number because 1st graders are not prepared to learn about negative numbers.  

If the user enters a number not between 1 and 12, open an alert window stating that it is an invalid number, and prompt them to enter a number again meeting the criteria. Finally, if the number entered is bellow 6, make the background color blue and the text white, if the number is above 6 make the background color red and the text yellow, and if the number is six then make the background color white and the text black.

* Should be in HTML language.

HINT: use a variable and a window.prompt() to store what the person enters, a conditional statement, and string concatenation using HTML as we discussed in class.

Solutions

Expert Solution

HTML & Javascript Code:

<html>
   <head>
       <script type="text/javascript">
           function processMath()
           {
               while(true)
               {
                   //Reading input and parsing it to integer
                   var num = parseInt(prompt("Please enter a number between 1 and 12", "0"));
                  
                   //Validating number
                   if(num < 1 || num > 12)
                   {
                       alert("Invalid Number");
                   }
                   else
                   {
                       break;
                   }
               }
              
               //Generating Addition and Subtraction
               document.writeln("</br> Addition Math Facts for " + num + " </br>");
               var i;
               for(i=1; i<=12; i++)
               {
                   document.writeln(num + " + " + i + " = " + (num+i) + " </br>");
               }
               document.writeln("</br> Subtraction Math Facts for " + num + " </br>");
               for(i=12; i>=num; i--)
               {
                   document.writeln(i + " - " + num + " = " + (i-num) + " </br>");
               }
              
               //Changing color
               if(num < 6)
               {
                   document.body.style.backgroundColor = "blue";
                   document.body.style.color = 'white';
               }
               else if(num > 6)
               {
                   document.body.style.backgroundColor = 'red';
                   document.body.style.color = 'yellow';
               }
               else
               {
                   document.body.style.backgroundColor = 'white';
                   document.body.style.color = 'black';
               }
              
           }  
              
       </script>
   </head>

   <body onload="processMath()">
      
   </body>
  
</html>

___________________________________________________________________________________________________

Sample Run:


Related Solutions

Write a Python program that will perform various calculations (addition, subtraction, multiplication, division, and average). The...
Write a Python program that will perform various calculations (addition, subtraction, multiplication, division, and average). The program will add, subtract, multiply, or divide 2 numbers and provide the average of multiple numbers inputted from the user. You need to define a function named performCalculation which takes 1 parameter. The parameter will be the operation being performed (+,-,*,/). This function will perform the given prompt from the user for 2 numbers then perform the expected operation depending on the parameter that’s...
Write a Java program to print the sum (addition), multiplication, subtraction, and division of two numbers....
Write a Java program to print the sum (addition), multiplication, subtraction, and division of two numbers. Start your code by copying/pasting this information into an editor like notepad, notepad++, or IDLE: public class Main { public static void main(String[] args) { // Write your code here } } Sample input: Input first number: 125 Input second number: 24 Sample Output: 125 + 24 = 149 125 - 24 = 101 125 x 24 = 3000 125 / 24 = 5...
Ahrithmetic calculation about scientific notation. Mixed unit and multiplication, addition, subtraction, division too. this is my...
Ahrithmetic calculation about scientific notation. Mixed unit and multiplication, addition, subtraction, division too. this is my question above, please help me I need it to study.
TheMathGame Develop a program in PYTHON that will teach children the basic math facts of addition....
TheMathGame Develop a program in PYTHON that will teach children the basic math facts of addition. The program generates random math problems for students to answer. User statistics need to be kept in RAM as the user is playing the game and recorded in a text file so that they may be loaded back into the program when the student returns to play the game again. In addition, the youngster should be allowed to see how (s)he is doing at...
What is the primary reason that addition and subtraction are considered more complex than multiplication and...
What is the primary reason that addition and subtraction are considered more complex than multiplication and division with floating-point representations? What are subnormal numbers, and how do subnormal numbers help reduce the impact of underflow?
In Visual Studio in C#, you will create a simple calculator that performs addition, subtraction, multiplication,...
In Visual Studio in C#, you will create a simple calculator that performs addition, subtraction, multiplication, and division. Your program should request a numerical input from the user, followed by the operation to be performed, and the second number to complete the equation. The result should be displayed to the user after each equation is performed. For example, if the user performs 3+3, the program should display 6 as the result. The program should continue running so the user can...
Write a Behavioral model VHDL code that implements an ALU that can perform addition, subtraction, multiplication,...
Write a Behavioral model VHDL code that implements an ALU that can perform addition, subtraction, multiplication, shift right, shift left, logical NAND, and logical NOR. Write a VHDL test bench to test the ALU with at least one test vector per operation.
Write a program named problem.c to generate addition and subtraction math problems for a 4th grader....
Write a program named problem.c to generate addition and subtraction math problems for a 4th grader. 1. Your program will first ask user how many problems they want to do. 2. Repeat the following until you give user the number of problems that the user asks for.   a. Display the question number b. Generate a addition or subtraction problem using two random generated two digits (0-99). - The odd number of problems (1,3,5,…) will be addition problems. - The even...
python please take it out from class and make it all functions, add subtraction and multiplication...
python please take it out from class and make it all functions, add subtraction and multiplication functions with it. than you so much for helping me out. import random image = 'w' class cal(): def __init__(self, a, b): self.a = a self.b = b def add(self): return self.a + self.b a = random.randint(0, 9) b = random.randint(0, 9) obj = cal(a, b) print("0. Exit") print("1. Add") choice = int(input("Enter choice: ")) cnt = 0 # To hold number of tries...
Gui calculator in Java with additon, subtraction, multiplication, division, sine, cosine, tangent, square, cube, raise to...
Gui calculator in Java with additon, subtraction, multiplication, division, sine, cosine, tangent, square, cube, raise to x to the power of y functionality. It should also have memory button, memory recall button and clear.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT