Task
Your client would like you to create a program for the Mathletics championships.
Mathletics takes 2 numbers and has to write down the mathematical equations for addition, subtraction, multiplication, division, floor division, modular division and exponents.
Create a program that will provide full output for each of the mathematical equations.
Solution
Instructions
Enter first number:
Enter second number:
Results
addition result here
subtraction result here
multiplication result here
division result here
floor division result here
modular division result here
exponents result here


Show Code
Code
| function calculate() { | |
| //get input from the user | |
| let x = parseFloat(document.getElementById(‘firstnum’).value); | |
| let y = parseFloat(document.getElementById(‘secondnum’).value); | |
| //display results | |
| document.getElementById(“mathletics-addition”).innerHTML = x + ” plus ” + y + ” = ” + (x+y); | |
| document.getElementById(“mathletics-subtraction”).innerHTML = x + ” minus ” + y + ” = ” + (x-y); | |
| document.getElementById(“mathletics-multiplication”).innerHTML = x + ” multiplied by ” + y + ” = ” + (x*y); | |
| document.getElementById(“mathletics-division”).innerHTML = x + ” divided by ” + y + ” = ” + (x/y); | |
| //Math.floor() rounds a number DOWN to the nearest integer: | |
| document.getElementById(“mathletics-floor-division”).innerHTML = x + ” floor divide by ” + y + ” = ” + Math.floor(x/y); | |
| document.getElementById(“mathletics-modular-division”).innerHTML = x + ” modulus divide by ” + y + ” = ” + (x%y); | |
| document.getElementById(“mathletics-exponents”).innerHTML = x + ” to the power of ” + y + ” = ” + (x**y); | |
| } |
