gat
May 22, 2022, 1:46pm
1
// Challenge
//1. Create an array(arr) with the numbers 1 to 10
//2. Create a filter that pushes the numbers from 4 to 9 to a new array(num)
// Solution
let const arr = [1,2,3,4,5,6,7,8,9,10];
let const num = [ ];
for (let i=0; i < arr.length; i++) {
if(arr[i] >= 4 && arr[i] <= 9) {
//console.log(arr[i]);
num.push(arr[i]);
}
}
It really helps if the post contains your questions.
Does this challenge want you to use the filter
method? If so, it is teaching an anti-pattern. You shouldn’t push to an external array with a filter. You directly create a new array from the old one.
gat
May 22, 2022, 1:56pm
3
Yea the question is the one right above the solution in the post.
I mean, it helps if you put your question, you specific part you need help with, in tme text of the post instead of the title.
Anyway, are they looking for you to use the filter method?
gat
May 22, 2022, 2:03pm
5
Ok I understand you now. I think the function “num.push(arr[i]);” in my solution is refusing to display.
gat
May 22, 2022, 2:07pm
6
Well can’t really tell but that is the question.
gat
May 22, 2022, 3:01pm
7
Yea I think i got it now. I only needed the display command - console.log(num); to show the “num” array content.
Thanks!
system
Closed
November 21, 2022, 3:02am
8
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.