Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript The Solution

Tural Rzazade
Tural Rzazade
3,397 Points

My solution to the challenge

at first, I was calculating the results of two inputs by using 4 different variables (because of 4 different calculations). then I realized from one of the students' codes that I could do it within the same template literals.

By the way, having these video materials from 2-3 years ago and also hearing the let, const, and var topics such as var is not preferred that much anymore makes me confused a little

// 1. Attach this file -- math.js -- to the index.html file using a <script> tag

// 2. Add an alert to announce the program with a message like "Let's do some math!"

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

// 3. Create a variable and use the prompt() method to collect a number from a visitor

const inputRawFirst = prompt("Provide a value");
const inputRawSecond = prompt("Provide another value");

// 4. Convert that value from a string to a floating point number

const inputFirst = parseFloat(inputRawFirst);
const inputSecond = parseFloat(inputRawSecond);


const messageFirst = `<h1>Math  with the numbers ${inputFirst} and ${inputRawSecond}<br></h1>
${inputFirst} + ${inputSecond} = ${inputFirst + inputSecond} <br>
${inputFirst} - ${inputSecond} = ${inputFirst - inputSecond} <br>
${inputFirst} * ${inputSecond} = ${inputFirst * inputSecond} <br>
${inputFirst} / ${inputSecond} = ${inputFirst / inputSecond} <br>
`;

document.write(messageFirst);