- 2
what will be the outcome for this function ?
function sum_odd(){ var sum = 0; for( var i = 5; i < 174; i++){ if(i % 2==1){ sum+=i; } }
33 Respuestas
+ 3
your function will sum all the numbers in the range from 5 to 173, which when divided by 2 will show the remainder of division 1
+ 3
The code will output the sum of odd numbers from 5 to 173
+ 2
Hello Tsering Kalden
You can put that snippet in a JS pane of a new Web code to find out the value of sum. Simply add `console.log(sum);` after the loop body, or you can just use an alert box to show value of <sum> variable.
+ 2
Do I need console.log(sum) at the end.
+ 1
I try input console.log in different variables, but nothing exit to the window. 🤔
And your code missing one "}"
+ 1
create another variable and assign it the value of the entire function. inside the function, add another line of code with the output of the sum variable. use the last line of code to display this new variable. did I make it clear?
+ 1
Hi @lpang.
i tried and it was nothing happen.
+ 1
Tsering Kalden
Can you share your code link here so I can see what's the problem?
* How to share links:
https://www.sololearn.com/post/74857/?ref=app
+ 1
He want to output sum. but I doubt that he wrote the code himself (judging by the two previous questions)
+ 1
How input code here:
If you want to run a code on Sololearn then,
➡️ Go to the Code Playground section (you can find it here : https://code.sololearn.com) and click on the + icon at the bottom right corner.
➡️ Then select Web and write your JS code in the JS section and save it.
➡️ Then click on Run and your Code will get executed.
+ 1
Tsering Kalden if you want to tag a user in a message, type @ and wait a bit (a pop - up window with names will appear soon)
+ 1
I managed to bring sum to the screen in a calm environment and with minimal code modification. if you haven't figured it out yet, ask me how 🤭 😉
+ 1
Console it bro, nobody gonna console it for you
+ 1
you need to do console.log(“Sum”, sum)
+ 1
I try
+ 1
1
+ 1
In range from 5 to 173
0
Just so you can see the value of variable <sum> Tsering Kalden
0
I had same issue. I tried different ways but nothing Ярослав Вернигора(Yaroslav Vernigora)
0
Ok let me try with that Ipang