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
John Wheeler
6,671 PointsBasic JavaScript - Extra Credit
This is my solution for the 'loops' extra credit assignment in the JavaScript Basics Course.
for (var counter=100; counter; counter = counter -1) {
var divideby3 = counter % 3;
var divideby5 = counter % 5;
if (divideby5 < 1 && divideby3 < 1) {
console.log("fizzbuzz")
}
else if (divideby5 < 1) {
console.log("buzz")
}
else if (divideby3 < 1) {
console.log("fizz")
}
else {
console.log(counter);
}
}
Fredrik August Madsen-Malmo
16,261 PointsIf you want to subtract one from the variable each time the loop runs you can type
counter--
or
counter -= 1
.
welcomeuniverse
1,942 Pointsfor (var counter=100; counter; counter = counter -1) {
Why are you using for lopp when this looks like a while loop will work better here?
var divideby3 = counter % 3;
var divideby5 = counter % 5;
if (divideby5 < 1 && divideby3 < 1) {
console.log("fizzbuzz")
}
else if (divideby5 < 1) {
console.log("buzz")
}
else if (divideby3 < 1) {
console.log("fizz")
}
else {
console.log(counter);
}
}
This look nice.However you may wanna use case for this one!
welcomeuniverse
1,942 Pointsfor (var counter=100; counter; counter = counter -1) {
Why are you using for lopp when this looks like a while loop will work better here?
var divideby3 = counter % 3;
var divideby5 = counter % 5;
if (divideby5 < 1 && divideby3 < 1) {
console.log("fizzbuzz")
}
else if (divideby5 < 1) {
console.log("buzz")
}
else if (divideby3 < 1) {
console.log("fizz")
}
else {
console.log(counter);
}
}
This look nice.However you may wanna use case for this one!
John Wheeler
6,671 PointsJohn Wheeler
6,671 PointsHere is the html for it