function sum(n){for(var i = 1;i>= 5;i++ ){ let n=0; n+=i;}} console.log(sum()) //where is the mistake .why does it not work? //t | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

function sum(n){for(var i = 1;i>= 5;i++ ){ let n=0; n+=i;}} console.log(sum()) //where is the mistake .why does it not work? //t

Tell where the mistake is please

3rd Mar 2021, 1:17 PM
Global Universe
Global Universe - avatar
55 Answers
+ 15
i<=5 💻
3rd Mar 2021, 5:17 PM
Sanjay Kamath
Sanjay Kamath - avatar
+ 7
There is no "return" in your function
3rd Mar 2021, 1:31 PM
Nazeekk
Nazeekk - avatar
+ 2
Ouch.. sorry about that. Just i was hurried and named it with the first thing i thought about😳😳
3rd Mar 2021, 5:17 PM
Nazeekk
Nazeekk - avatar
+ 2
Patel Ashish we solve it already😃
5th Mar 2021, 5:46 AM
Nazeekk
Nazeekk - avatar
+ 1
*to have👆
3rd Mar 2021, 1:41 PM
Global Universe
Global Universe - avatar
+ 1
Well, check my code again, i remade it again 😂😂😂
3rd Mar 2021, 3:40 PM
Nazeekk
Nazeekk - avatar
+ 1
Thanks, i did it😃
3rd Mar 2021, 6:25 PM
Nazeekk
Nazeekk - avatar
0
Let me try it . Thanks
3rd Mar 2021, 1:32 PM
Global Universe
Global Universe - avatar
0
Try it. If that's the thing you wanna get🤔
3rd Mar 2021, 1:38 PM
Nazeekk
Nazeekk - avatar
0
Thanks so much it so good to people like you
3rd Mar 2021, 1:40 PM
Global Universe
Global Universe - avatar
0
Hi Nazeek after some tinkering I managed to make add all integers up to n https://code.sololearn.com/WX2Dfe1JckHG/?ref=app
3rd Mar 2021, 2:36 PM
Global Universe
Global Universe - avatar
0
Yeap, thats kinda smart😃 I think you can also do it available for users to choose a number. The easiest way is to use "prompt" i guess 🤔🤔
3rd Mar 2021, 2:38 PM
Nazeekk
Nazeekk - avatar
0
Iam still still a novice to be honest. I don't know how it's done
3rd Mar 2021, 2:40 PM
Global Universe
Global Universe - avatar
0
Nazeekk please, stop using expletives anywhere.
3rd Mar 2021, 2:44 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
Wow😅 That's a function to get user input. Just like: let x = prompt() alert(x) So here when we enter data, the "x" variable will have user's value
3rd Mar 2021, 2:46 PM
Nazeekk
Nazeekk - avatar
0
Nazeekk Let me incorporate that into my code thanks
3rd Mar 2021, 2:48 PM
Global Universe
Global Universe - avatar
0
Check my link again. I remade it😃😃 So.. as i can get, you made smth kinda "factorial calculator"?🤔
3rd Mar 2021, 2:50 PM
Nazeekk
Nazeekk - avatar
0
Ok
3rd Mar 2021, 2:51 PM
Global Universe
Global Universe - avatar
0
Wow 😃 it works
3rd Mar 2021, 2:53 PM
Global Universe
Global Universe - avatar