Skip to content

Accelerator-labs/lab-loops

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

JavaScript Looping Drills

Overview

You'll practice working with for loops, while loops, and control the flow of execution to repeat certain actions multiple times.

Instructions:

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.


For Loops

  1. Count to Ten
    Write a program that prints the numbers from 1 to 10 using a for loop.

  2. Even Numbers Only
    Write a program that prints all even numbers between 1 and 20.

  3. Reverse Counting
    Write a program that prints numbers from 10 to 1 in reverse order.

  4. Sum of Numbers
    Write a program that calculates the sum of all numbers from 1 to 50.

  5. Multiples of 3
    Write a program that prints all multiples of 3 from 1 to 30.

  6. Print Squares
    Write a program that prints the square of each number from 1 to 5.

  7. Factorial Calculation
    Write a program that calculates the factorial of a given number using a for loop.

  8. Print Numbers Divisible by 5
    Write a program that prints all numbers between 1 and 20 that are divisible by 5.

  9. Print Odd Numbers
    Write a program that prints all odd numbers between 1 and 20.

  10. Print Numbers Divisible by 4
    Write a program that prints all numbers between 1 and 20 that are divisible by 4.

  11. 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.).

  12. Sum of Even Numbers
    Write a program that sums all even numbers from 1 to 100 and prints the result.

  13. Reverse Word Print
    Write a program that prints a string in reverse using a for loop (without using built-in reverse methods).

  14. Number Pyramid
    Write a program that prints a pyramid pattern using numbers (e.g., 1, 22, 333, 4444, etc.).

  15. Prime Number Checker
    Write a program that checks if a number is prime by using a for loop and prints “Prime” or “Not Prime”.


While Loops

  1. While Counting
    Write a program that prints numbers from 1 to 5 using a while loop.

  2. Infinite Loop
    Write a program that runs an infinite while loop until a specific condition is met (e.g., user input or a counter reaches a certain number).

  3. Countdown with While Loop
    Write a program that counts down from 5 to 1 using a while loop.

  4. Sum of Odd Numbers
    Write a program that sums all odd numbers from 1 to 50 using a while loop 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! 🚀

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%