Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript The Solution

Khashayar Mirbabaie Ghane
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Khashayar Mirbabaie Ghane
Full Stack JavaScript Techdegree Graduate 27,891 Points

My solution is a bit different and I think easier !

alert("Hello and welcome,let's do little math !");

const firstnumber = parseFloat(prompt('Enter your first number please'));
const secondnumber = parseFloat(prompt('Enter your first number please'));

const sumnumbers = firstnumber + secondnumber;
const minusnumbers = firstnumber - secondnumber;
const dividenumbers = firstnumber / secondnumber ;
const multiplenumbers = firstnumber * secondnumber;

const main = document.querySelector('main');
main.innerHTML = `
<h1>your numbers are ${firstnumber} and ${secondnumber}, so these are the calculations:</h1>
<br>
<p> the sum of ${firstnumber} + ${secondnumber} = ${sumnumbers}
<p> the minus of ${firstnumber} - ${secondnumber} = ${minusnumbers}
<p> the divide of ${firstnumber} / ${secondnumber} = ${dividenumbers}
<p> the multiple of ${firstnumber} * ${secondnumber} = ${multiplenumbers}
`;

3 Answers

Brandon Jones-Harris
Brandon Jones-Harris
6,713 Points

alert("Let's do some Math!")

const inputOne = prompt("What is your first number?"); const numOne = parseFloat(inputOne);

const inputTwo = prompt("What is your second number?"); const numTwo = parseFloat(inputTwo);

const message = (<h1>Math with the numbers ${numOne} and ${numTwo}</h1> ${numOne} + ${numTwo} = ${numOne + numTwo} <br> <br> ${numOne} * ${numTwo} = ${numOne * numTwo} <br> <br> ${numOne} / ${numTwo} = ${numOne / numTwo} <br> <br> ${numOne} - ${numTwo} = ${numOne - numTwo});

document.write(message);

clean.. I like it. well done.

I did something similar by making use of ${} inside of ``.