Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions 04week/loop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Use a for loop to console.log each item in the array carsInReverse
const carsInReverse = ['Ford', 'Honda', 'Lincoln', 'Chevy'];

for(let i = 0; i < carsInReverse.length; i++){
console.log(carsInReverse[i]);
}


// Create an object (an array with keys and values) called persons with the following data:
const persons = {
firstName: "Jane",
lastName: "Doe",
birthDate: "Jan 5, 1925",
gender: "female"
};

const keys = Object.key(persons)
// Use a for...in loop to console.log each key.
for (const prop in persons) {
console.log(`${prop} = ${persons[prop]}`);
};

// Then use a for...in loop and if state, to console.log the value associated with the key birthDate
keyBirth = persons.birthDate

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keybirth is not defined .


for(const prop in keyBirth){
if(keyBirth==prop.birthDate)
console.log(`${prop} = ${keyBirth[prop]}`)
}


// Use a for loop to console.log the numbers 1 to 1000 (while loop)
let loopNum = 1;
while (loopNum < 1001){
loopNum += 1;
console.log(loopNum);
}