You'll practice working with for loops, while loops, and control the flow of execution to repeat certain actions multiple times.
In loops.js for each prompt, write a JavaScript program that solves the problem using the appropriate type of loop. Make sure to run the program in your terminal to check if it works as expected.
-
Count to Ten
Write a program that prints the numbers from 1 to 10 using aforloop. -
Even Numbers Only
Write a program that prints all even numbers between 1 and 20. -
Reverse Counting
Write a program that prints numbers from 10 to 1 in reverse order. -
Sum of Numbers
Write a program that calculates the sum of all numbers from 1 to 50. -
Multiples of 3
Write a program that prints all multiples of 3 from 1 to 30. -
Print Squares
Write a program that prints the square of each number from 1 to 5. -
Factorial Calculation
Write a program that calculates the factorial of a given number using aforloop. -
Print Numbers Divisible by 5
Write a program that prints all numbers between 1 and 20 that are divisible by 5. -
Print Odd Numbers
Write a program that prints all odd numbers between 1 and 20. -
Print Numbers Divisible by 4
Write a program that prints all numbers between 1 and 20 that are divisible by 4. -
Exponential Growth
Write a program that prints the result of raising 2 to the power of each number from 1 to 5 (i.e., 2^1, 2^2, 2^3, etc.). -
Sum of Even Numbers
Write a program that sums all even numbers from 1 to 100 and prints the result. -
Reverse Word Print
Write a program that prints a string in reverse using aforloop (without using built-in reverse methods). -
Number Pyramid
Write a program that prints a pyramid pattern using numbers (e.g., 1, 22, 333, 4444, etc.). -
Prime Number Checker
Write a program that checks if a number is prime by using aforloop and prints “Prime” or “Not Prime”.
-
While Counting
Write a program that prints numbers from 1 to 5 using awhileloop. -
Infinite Loop
Write a program that runs an infinitewhileloop until a specific condition is met (e.g., user input or a counter reaches a certain number). -
Countdown with While Loop
Write a program that counts down from 5 to 1 using awhileloop. -
Sum of Odd Numbers
Write a program that sums all odd numbers from 1 to 50 using awhileloop and prints the result.
Submission:
- Complete all drills in the file.
- Push your work your forked copy, create a pull request on the original repo, and then submit your URL on Google Classroom.
- Be prepared to explain how your code works.
Happy coding and good luck! 🚀