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

JS math project - sharing my code

so I am feeling good about this,... however I also feel there could be some other ways to make the code smaller and still function well, what do you think. .. .

also i was trying that three backticks thing to show code as it should be .. .

alert("Hi, Let's do some math!");

const yourFirstNumber = prompt("Give me a number please.");
const yourSecondNumber = prompt("Give me a second number please.");


const additionTotal = parseInt(yourFirstNumber) + parseInt(yourSecondNumber);
const multiplicationTotal = parseInt(yourFirstNumber) * parseInt(yourSecondNumber);
const divisionTotal = parseInt(yourFirstNumber) / parseInt(yourSecondNumber);
const minusTotal = parseInt(yourFirstNumber) - parseInt(yourSecondNumber);

const main = document.querySelector('main');

main.innerHTML = `<h1>You have chosen numbers ${yourFirstNumber} and ${yourSecondNumber}.</h1>
<h2> Addition: ${yourFirstNumber} + ${yourSecondNumber} = ${additionTotal}</h2>
<h2>Multiplication: ${yourFirstNumber} * ${yourSecondNumber} = ${multiplicationTotal}</h2>
<h2>Division: ${yourFirstNumber} / ${yourSecondNumber} = ${divisionTotal}</h2>
<h2>Minus: ${yourFirstNumber} - ${yourSecondNumber} = ${minusTotal}</h2>`;

2 Answers

Steven Parker
Steven Parker
231,248 Points

There's rarely only one way to program a solution. The fact that you're seeing alternatives for more compact and/or efficient solutions is evidence of your learning progress. :+1:

thanks, that's very encouraging especially after a long spade of feeling like you don't get it .. . and when you do, you still don't believe you do ... lol