In this case, i want to display the length of output from the user input using “for loop”.
let value = []
const getTotalDisp = (input) => {
for(let i=1; i<input; i++){
if(i%2===0){
value.push(i)
}
}
return value
}
console.log(getTotalDisp (10))
this would be display :
[2,4,6,8]
and what i expected the output display is if user input 10, then the output length must be ten numbers like :
[2,4,6,8,10,12,14,16,18,20]
How should i do to set the condition of it ? i tried to add some condition before “for loop” like this :
let value = []
const getTotalDisp = (input) => {
if(value.length<input){
for(let i=1; i<input; i++){
if(i%2===0){
value.push(i)
}
}
return value
}
}
console.log(getTotalDisp (10))
but it doesn’t work. Could anyobdy help me to solve this? Thanks.