Loop Js

use a for loop to solve the following problems

  1. Write a for loop that will iterate from 0 to 20. For each iteration, it will check if the current number is even or odd, and console.log the result (e.g. "2 is even").

  2. Define a variable named myBagOfBeans and set it equal to fifty. loop down from a hundred and if the number is even add the current value to myBagOfBeans.

  3. Loop through this array, and seperate the drinks, the food, and the sauces into seperate arrays.

const arrayOfStringsRememberIcanNameMyVariablesAnythingIWant = ['cheese', 'pepperoni', 'sausage', 'coca cola', 'lemonade', 'dough', 'beer', 'wine', 'ranch', 'blue cheese', 'bbq sauce'];

  1. Loop through the following array and push the items that are not numbers into a seperate array

const mixedArray = [1, 2, 3, 'taco', 4, 5, 6, 'burrito', 7, 8, 9, 'Whats the deal with airplane peanuts', 3.14, {barry: "Mannilow",}, 6, 55, null, "Old " + "Crow " + " Medicine Show", 3, 2, "I want the calzone from pizanos", "Death blow", "Firestorm", "48", 30]

  1. Loop through the following array and push the items that make up a cheese burger, or spaghetti into a seperate array name dinner.

const food = ['bun', "jalepeno cheddar", "elk", "beef", "1954 ford mustang", 1.14, 1.23, 'hot dog', "gary clark jr", " I'lll never fall in love again", "mustard", "ketchup", 30, 50, 80, "grilled onions", "egg", "Dr. Suess"]

Use a for in loop to loop through the following objects and print to the console,

the name of each property.

  1. const colorObjects = {red: 'red', blue: 'blue', cyan: 'cyan'}

  2. const seinfeld = {cosmo: "kramer", jerry: "Seinfeld", george: "constanza", elaine: "bennis"}

  3. const profile = {name: "Elon Musk", occupation: "space man", hobbies: ["paypal", "space X", "rocket science"]}

Use a for loop or a for in loop and print out the properties of the object or value of the indexin the array, Above your code write in a comment what loop you are using and why

  1. const oldTime = ["benton flippen", "carter family", "roscoe Holcomb", "gus cannon", "Tommy Jarrell"];

  2. const sandwhich = {name: "sunday morning special", bread: "ciabatta", cheese: "pepper jack", green: "arugala", redStuff: "cherry tomatoes", heated: true}

  3. const zeppelin = ["In through the out door", "Zep 1", "Zep 2", "Zep3", "Zep4", "Physical Graffiti"]

results matching ""

    No results matching ""