Skip to content

Commit

Permalink
Thomas Nielsen
Browse files Browse the repository at this point in the history
  • Loading branch information
thomamn committed Oct 1, 2024
1 parent 09459ce commit f6f2690
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/for-loop-and-arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,37 @@ let word = '' // eslint-disable-line prefer-const

// 1. Use a for loop to set the sum variable to the sum of all the values in nums

for (let i = 0; i < nums.length; i++) {
sum += nums[i]
}

// 2. Use a for loop to populate doubledNums with every value from nums array doubled (i.e [2, 6, 24, etc...])
const doubledNums = []

for (let i = 0; i < nums.length; i++) {
doubledNums.push(nums[i] * 2)
}

// 3. Use a for loop to set word variable equal to all the letters in the letters array combined as a single string

for (let i = 0; i < letters.length; i++) {
word += letters[i]
}

// 4. Use a for loop to populate everySecondNum with every second number from the nums array
const everySecondNum = []

for (let i = 1; i < nums.length; i += 2) {
everySecondNum.push(nums[i])
}

// 5. Use a for loop to populate numsReversed with the numbers from nums in reverse order
const numsReversed = []

for (let i = nums.length - 1; i > -1; i--) {
numsReversed.push(nums[i])
}

// do not change below this line
module.exports = {
a: sum,
Expand Down
17 changes: 17 additions & 0 deletions src/for-loop-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,33 @@ const countdown = []

// TODO: 1. Write a for loop that adds the numbers 0 to 3 to the numsZeroToThree array

for (let i = 0; i < 4; i++) {
numsZeroToThree.push(i)
}

// TODO: 2. Write a for loop that adds the numbers 5 to 10 to the numsFiveToTen array

for (let i = 5; i < 11; i++) {
numsFiveToTen.push(i)
}

// TODO: 3. Write a for loop that adds all the even numbers between 0 and 6 (0, 2, 4, 6) to evenNums

for (let i = 0; i < 7; i += 2) {
evenNums.push(i)
}

// TODO: 4. Write a for loop that adds the numbers 3 to 0 (in that order) to the countdown array

for (let i = 3; i > -1; i--) {
countdown.push(i)
}

// do not change below this line
module.exports = {
a: numsZeroToThree,
b: numsFiveToTen,
c: evenNums,
d: countdown
}

0 comments on commit f6f2690

Please sign in to comment.