Loop Js
use a for loop to solve the following problems
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").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.
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'];
- 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]
- 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.
const colorObjects = {red: 'red', blue: 'blue', cyan: 'cyan'}
const seinfeld = {cosmo: "kramer", jerry: "Seinfeld", george: "constanza", elaine: "bennis"}
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
const oldTime = ["benton flippen", "carter family", "roscoe Holcomb", "gus cannon", "Tommy Jarrell"];
const sandwhich = {name: "sunday morning special", bread: "ciabatta", cheese: "pepper jack", green: "arugala", redStuff: "cherry tomatoes", heated: true}
const zeppelin = ["In through the out door", "Zep 1", "Zep 2", "Zep3", "Zep4", "Physical Graffiti"]