0
Simple code not working??
8 Answers
+ 4
You've used the return statement inside the loop. As soon as the control enters the loop, it does the calculation and meets the return statement, so the function ultimately returns the value, and further execution of the loop is discontinued. Move the return statement outside of the loop.
Happy coding <^_^>
+ 1
i have another question
https://code.sololearn.com/WSPtUOs8GFeH/?ref=app
+ 1
thatkidayo
According to your new question, i++ and ++i, both have same work, that is to increment i by 1.
The difference here is, if you use an expression with these, they'll behave differently, otherwise, they will have same meaning like i=i+1.
Consider these
//case 1
var i = 5;
console.log(i++);
console.log(i);
//case 2
var i = 5;
console.log(++i);
console.log(i);
See the output of these two cases.. you'll get what I'm saying.
i++ will give the previous value of i in the statement where it is used, and then i+1 from next statement onwards.
And ++i will give i+1 immediately.
You can experiment by using them in different arithmetic expressions.
+ 1
oops i asked the wrong questionđ
please check it againđđđđ
https://code.sololearn.com/WSPtUOs8GFeH/?ref=app
+ 1
thatkidayo
Just remove the i++ from the for statement.
It will look like this
for(i=0;i<number-1;)
this is because, you are incrementing i twice in a single run.. that's why its not showing all values.
Happy Coding <^_^>
off topic - (https://www.youtube.com/c/everythingcomputerized)
+ 1
thanks a lotđ
ill checkout the youtube channel
0
thatkidayo thank youâș
0
for(i=0;i<number;i++){
let num=i+1;
arr[i]=num;
Use this