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<noob />
17,062 PointsHelp in Javascript question
The question: Read numbers, until the number 999 is entered. For each number:
a) Print if it’s divided by 3
b) Print whether this num is much bigger (more than 10) than the previous number.
i tried to solve it but its 50% working , i dont know why evreytime the previous number is the same as the currentNum and how i print for each number the log in a loop correctly?
what i did:
let differnce = 0;
let currentNum;
let previousNum;
while(currentNum !== 999) {
currentNum = parseInt(prompt("Enter a number"));
if(!previousNum) {
previousNum = currentNum;
}
console.log("current num: ", currentNum);
console.log("previous num: " , previousNum);
differnece = currentNum - previousNum;
if(currentNum % 3 === 0) {
console.log(`${currentNum} can be divided by 3`);
}
else if(differnce > 10) {
console.log(`${currentNum} is much higher than the previous num: ${previousNum}`);
} else {
console.log("none of the condiots have been met");
}
previousNum = currentNum;
}
i will be happy to get a hint/help..
2 Answers
Steven Parker
231,172 PointsOK, here's a hint: "orthography".
.
.
.
.
.
So if you haven't already figured it out, "orthography" means "spelling". This code has "differnece" in one place and "differnce" in another (and you probably meant to put "difference" for both of them).
And a way to display messages that plays well with "prompt" is "alert". They both use modal dialogs that other methods can't compete with.
Tommy Gebru
30,164 PointsCheck your spelling, when coding your typos and mistakes are not always accounted for!
Steven Parker
231,172 PointsSteven Parker
231,172 PointsPlease give the community some time to respond before tagging anyone specifically.