Why? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1
13th May 2021, 11:53 AM
Alexander Sokolov
Alexander Sokolov - avatar
18 Answers
+ 4
var a = { b:0 } function t(a) { a.b++; return a.b; } setInterval(function(){ console.log(t(a)) }, 2000);
13th May 2021, 12:53 PM
Reivin
Reivin - avatar
+ 2
var a = 1 //function function t(a) { while (a<5){ a++; console.log(a); } } //setInterval setInterval(function() { t(a); }, 2000);
13th May 2021, 12:56 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
Hi! and how would you like it to increase?
13th May 2021, 12:10 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
what do you mean? I just want to increase the number in the object through a function, but for some reason it does not work ... 😭
13th May 2021, 12:12 PM
Alexander Sokolov
Alexander Sokolov - avatar
+ 1
Sir, please please see my code ... 😭😭😭
13th May 2021, 12:13 PM
Alexander Sokolov
Alexander Sokolov - avatar
+ 1
if you want to output a sequence of numbers, use a loop inside the function. if you just want to increase a by 1, then do this: ... a++; return a
13th May 2021, 12:15 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
and you will have 2 with enviable constancy...
13th May 2021, 12:16 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
But how to make the number increase infinitely?
13th May 2021, 12:18 PM
Alexander Sokolov
Alexander Sokolov - avatar
+ 1
use a loop where the condition will always be true. are you from India, by any chance?
13th May 2021, 12:21 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
and codes with infinite loops are not welcome here. please do not place programs with infinite loops in the code area (code playground { })
13th May 2021, 12:23 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
dude, no, you don't get it. First of all, what's the difference where I come from? for that matter, my profile says where I am from. secondly, I seem to have clarified my question. i want to increment a number in an object, but it does not work.
13th May 2021, 12:28 PM
Alexander Sokolov
Alexander Sokolov - avatar
+ 1
I’m not going to do it on codeplayground, who even told you that?
13th May 2021, 12:34 PM
Alexander Sokolov
Alexander Sokolov - avatar
+ 1
well, you increase it by an increment of 1, then insert the number 1 as a parameter into the function. you call the function and the function increases the number to 2. then you output it to the console with an interval. to constantly increase the number, use a loop. do you know what a cycle is?
13th May 2021, 12:35 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 1
I just warned you. you can use this kind of code, but keep it private
13th May 2021, 12:37 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
And how to increase more than 2?
13th May 2021, 12:39 PM
Alexander Sokolov
Alexander Sokolov - avatar
0
Yaroslav Vernigora How to increase the number in an object "a" via function arguments?
13th May 2021, 12:45 PM
Alexander Sokolov
Alexander Sokolov - avatar
14th May 2021, 11:32 AM
Naga Raju K
0
Naga Raju K thx, but me helped.
14th May 2021, 11:38 AM
Alexander Sokolov
Alexander Sokolov - avatar