Tell us what’s happening:
Can anybody tell me what I’ve done wrong
Your code so far
// Setup
var myArray = [];
// Only change code below this line
var i = 0;
while(i < 5) {
myArray.push(i)
i++;
}
Your browser information:
User Agent is: Mozilla/5.0 (Linux; Android 9; LM-X420) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Mobile Safari/537.36
.
Challenge: Iterate with JavaScript While Loops
Link to the challenge:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
ILM
September 5, 2020, 9:00pm
2
you are adding numbers to the array from 0 to 4, instead you need to add them from 5 to 0
Add the numbers 5 through 0 (inclusive) in descending order to myArray
using a while
loop.
you need to change something
Hi @adeniyi.oye ,
Just like @ILM have said, you need to add them to the new array, in addition since the challenge has stayed.
You need an initial variable “i” assigned to decrement.
in your while condition you must have “i” to be “true” .
Lastly since its descending order you must decrement the value of “i”.
bafian
September 5, 2020, 11:02pm
4
Hi,
Remember that under your script you can write down console.log(myArray)
so you can see the output while you try to figure it out !
Tell us what’s happening:
I tried everything even warätched the tutorial still didnt get the answer
Your code so far
// Setup
var myArray = [];
// Only change code below this line
var i = 5;
while(i <= 5)
while(i <= 4)
while(i <= 3)
while(i <= 2)
while(i <= 1)
while(i <= 0) {
myArray.push(i)
i++;
}
console.log(myArray)
Your browser information:
User Agent is: Mozilla/5.0 (Linux; Android 9; LM-X420) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Mobile Safari/537.36
.
Challenge: Iterate with JavaScript While Loops
Link to the challenge:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
ILM
September 7, 2020, 6:27pm
7
you are not using the while loop correctly
the while loop syntax is simple:
while (/* condition */)
/* code to repeat each time the condition is true */
}
are you using this syntax?
I see you have many times the while (...)
part, you need it only once
1 Like
Hi @adeniyi.oye
I think there are some good things we can do here:
You should only do one while loop. just like @ILM said
while (/* condition */)
/* code to repeat each time the condition is true */
}
In that while loop condition you should have your initial variable to be greater and = to 0.
while (initial variable (i) should be greater than and equal to 0)
/* code to repeat each time the condition is true */
}
When you finish looping with while loop, you should decrement the initial variable, instead of increment.
i--;
Hope this helps.
Tell us what’s happening:
Why isnt my code running. Imä’m confused
Your code so far
// Setup
var myArray = [];
// Only change code below this line
var i = 5;
while(i >= 0) {
myArray.push(i)
i++;
}
console.log(myArray)
Your browser information:
User Agent is: Mozilla/5.0 (Linux; Android 9; LM-X420) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Mobile Safari/537.36
.
Challenge: Iterate with JavaScript While Loops
Link to the challenge:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
ILM
September 8, 2020, 6:50pm
10
you have an infinite loop
your i
starts at 5
it’s increased at each iteration
and i >= 0
is always true