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

If statement in this exercise

I was wondering how you would check if the inputs from the user were equal to a numeric value.

How would the if statement look like? Can you use the following for example?

if ( number1 && number2 != parseInt() ) { alert("Please enter a number"); }

I don't know if the parseInt is appropriate but I'm just curious in what ways you can check this.

1 Answer

javascript
if ( number1 && number2 != parseInt() ) { alert("Please enter a number"); }

First - you need to evaluate every condition separately , then add the condition &&, you logic make sense to me, but not to the javascript interpreter.

>> number1 != parseInt() && number2 != parseInt()

Second - you are right parseInt() requires a parameter, and it must be present when you call for parseInt... so it should be something like:

>> parseInt(numberPicked,10);

third - the alert will show and it will ask, but there is no request to enter a number,

>>you need to use prompt()

most importantly, and I think what you are looking for as an answer: javascript interpreter scan the file, notice the variables, and "mark them" but doesn't store them, and read and store functions, look for articles about **Hoisting*

Best Luck !