Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this assignment, we’re going to create our own little math application, so s

ID: 3730183 • Letter: F

Question

For this assignment, we’re going to create our own little math application, so start off by creating an HTML page named mathApp.html using the standard course template. Title it whatever you like and place a element inside of your element. This is where you’ll write your JavaScript.

1. Inside of yourscript element, declare a global variable called result that will hold the result for the arithmetic operations which will be performed. Create another global variable to determine which question number you are on (don’t forget to assign this variable to 0).

2. Next, create a function called namePrompt that we’ll use to introduce our users to the application and greet them. Inside of the namePrompt function, create a prompt that will ask the user for their name and store the user’s input inside of a local variable.

3. Create a welcome message for the user, using their input, and display it in the console. Note the console is only visible in the browser if you enable it. In Chrome, it’s found under the developer tools.

4. Now, let’s move down to the tag and add the attribute as an event handler inside of the body tag itself and set it equal to “namePrompt()”, including the quotations.

5. While we’re down in the , create an element and declare the type as, “button”, the value as, “+”, and the onclick event as, “generateAddition()”.

6. Now, move back up to your script element and create another function named generateAddition.

7. First things first, increment your question number global variable by 1. Next, create two local variables to hold the two independent arguments for the arithmetic operation you will be performing. We’re going to want these numbers to be randomly generated each time we call the function, so use the Math class, invoking the .floor() and .random() function calls to generate these random numbers. Make sure your numbers are at least between 0 and 10 (hint: multiplying the number returned by Math.random() will return a number between 0 and that number).

8. Use another prompt to display the arithmetic problem to the user and store their response in a local variable. Compute the arithmetic operation, storing the result in your result global variable, and use a conditional to determine whether they got the correct answer or not to the console along with the question number they are currently on.

9. Now, do the same for subtraction, multiplication, and division. When handling the division arithmetic operation, ensure that the second argument isn’t a 0 and that the resulting answer is a whole number (hint: you may find a while loop and the modulus operator “%” useful here).

Explanation / Answer

Hi.. I have implemented above in html. Please check below.

Sample.html

<html>
<head>
<title>Sample</title>
<script type="text/javascript">
var result = 0;
var questionnumber = 0;

function namePrompt(){
var person = prompt("Please enter your name", "");
console.log("Welcome "+person);
}
function generateAddition(){
questionnumber++;
var first = Math.floor(Math.random() * 10);
var second = Math.floor(Math.random() * 10);
result = first+second;
console.log("Addition of "+first+"+"+second+"="+result);
}
function generateSubstraction(){
questionnumber++;
var first = Math.floor(Math.random() * 10);
var second = Math.floor(Math.random() * 10);
result = first-second;
console.log("Substraction of "+first+"-"+second+"="+result);
}
function generateMultiplication(){
questionnumber++;
var first = Math.floor(Math.random() * 10);
var second = Math.floor(Math.random() * 10);
result = first*second;
console.log("Multiplication of "+first+"*"+second+"="+result);
}
function generateDivison(){
questionnumber++;
var first = Math.floor(Math.random() * 10);
var second = Math.floor(Math.random() * 10);
if(second==0){
second++;
}
result = first/second;
console.log("Multiplication of "+first+"/"+second+"="+result);
}

</script>
</head>
<body>
<input type="button" name="add" value="+">&nbsp;
<input type="button" name="sub" value="-">&nbsp;
<input type="button" name="mul" value="*">&nbsp;
<input type="button" name="divide" value="/">&nbsp;
</body>
</html>

Please test the code and let me know any issues. Thank you. All the best.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote