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.

* must use HTML and java script. Must make program in brackets.

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

Solutions

Expert Solution

If you have any doubts, please give me comment...

<!DOCTYPE html>

<html>

<head>

    <title>Basic math</title>

</head>

<body>

    <div id="results"></div>

    <script type="text/javascript">

        function showMath() {

            var n = prompt("Enter number from 1 to 12: ");

            if (n < 1 || n > 12) {

                n = alert("Invalid number! It must be between 1 and 12");

                n = prompt("Enter number from 1 to 12: ");

            }

            if (n < 6) {

                document.getElementById("results").style.backgroundColor = "blue";

                document.getElementById("results").style.color = "white";

            } else if (n > 6) {

                document.getElementById("results").style.backgroundColor = "red";

                document.getElementById("results").style.color = "yellow";

            }

            var str = "";

            str = "<b>Addition Math Facts for \"" + n + "\"</b>";

            for (i = 1; i <= 12; i++)

                str += "<div>" + n + " + " + i + " = " + (i + n) + "</div>";

            str += "<b>Subtraction Math Facts for \"" + n + "\"</b>";

            for (i = 12; i >= n; i--)

                str += "<div>" + n + " - " + i + " = " + (i - n) + "</div>";

            document.getElementById("results").innerHTML = str;

        }

        showMath();

    </script>

</body>

</html>


Related Solutions

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...
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.
C -Language Create a simple calculator that performs addition, subtraction, multiplication, and division. Your program should...
C -Language Create a simple calculator that performs addition, subtraction, multiplication, and division. Your program should prompt the user for the operation they wish to perform followed by the numbers they wish to operate on. You should have a function for each operation and use branches to determine which function to call. I need this to make any integers given, into decimal numbers, such as 3 to 3.0, or 2 to 2.0, also, so that I can multiply or add...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT