Beginner Friendly Exercises for practicing JavaScript For and While Loops?
FAQ: Loops - The While Loop
Exercise loop "while" - JavaScript - Stack Overflow
Beginner working through Eloquent Javascript having a challenging time. Any suggestions for me?
I’ve been on a self-teaching journey for months learning html, css and now JavaScript. By some miracle, I’ve been able to learn the basics of some JavaScript concepts and unfortunately fell into a bit of a ditch with learning for and while loops in JavaScript. It was suggested to me (through a coding community) that I avoid practicing the blend of arrays and loops until I fully understand the basics of loops. So far I’ve been pulling through learning JavaScript through building super small and simplified things but I’ve been struggling to find good exercises online and via chat GPT that practice loops without the integration of arrays.
The only two possible exercises I saw was to
-
code a loop that counts to a certain number and
-
code a loop that displays a message beside all even numbers within a loop that has a range of numbers (i.e 1-10)
Does anybody else here learning web development have any valuable resources they can share surrounding loops?
I’m usually more of a visual learner and have a reputation for being horrible at math but I’m very determined to find a way to understand loops that makes sense in my ADHD brain and would appreciate any assistance. :)
You can simply add a seperate index counter for the case counting. Something like this:
function main() {
var i = 1;
var j = 1;
while(i <= 64){
document.write("Case " + j + " : " + i + " notes" + "<br>");
i = i*2;
j++;
}
}
main();
Try with this:
function main() {
var i = 0;
while (i < 4) {
document.write('Case ' + (i + 1) + ' : ' + Math.pow(2, i) + ' Notes');
i += 1;
}
}