JavaScript The Solution

Myles Magee
Myles Magee
2,549 Points

My solutions different but works lol

const start = alert('Lets do some math!');

let userFirstNum = prompt('Type a number that you want to add, subtract, multiple, and divide..');

let userSecondNum = prompt('Type another number to add, subtract, multiple, and divide from..');

let main = document.querySelector('body'); let message;

userFirstNum = parseFloat(userFirstNum); userSecondNum = parseFloat(userSecondNum);

function calculate(first, second) { let add = first + second; let subtract = first - second; let multi = first * second; let divide = first / second;

let addMessage = <li>${first} + ${second} = ${add}</li>; let subMessage = <li>${first} - ${second} = ${subtract}</li>; let multiMessage = <li>${first} * ${second} = ${multi}</li>; let divideMessage = <li>${first} / ${second} = ${divide}</li>;

message = addMessage + subMessage + multiMessage + divideMessage;

main.innerHTML = <h1>Calculations for the numbers ${first} and ${second}:</h1> <h2><ul>${message}</ul></h2>; }

calculate(userFirstNum, userSecondNum);