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 trialKhashayar Mirbabaie Ghane
Full Stack JavaScript Techdegree Graduate 27,891 PointsMy 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
6,713 Pointsalert("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);
Lewis Sheeran
Web Development Techdegree Graduate 19,398 Pointsclean.. I like it. well done.
I did something similar by making use of ${} inside of ``.
Tsipporah Christopher
Full Stack JavaScript Techdegree Graduate 15,593 PointsI like this way better! Thank you for sharing your solution!
Khashayar Mirbabaie Ghane
Full Stack JavaScript Techdegree Graduate 27,891 Pointscheers , glad it was helpful .
Khashayar Mirbabaie Ghane
Full Stack JavaScript Techdegree Graduate 27,891 PointsKhashayar Mirbabaie Ghane
Full Stack JavaScript Techdegree Graduate 27,891 Pointsi dont know it didnt get copy well or what but im gettin 18 errors on your code :D