Here's a developer's question | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 10

Here's a developer's question

How can the code below which was written in Python be written in JavaScript? x = 111 for i in range(5): x= x+2 print(x) x= x+4 print (x)

20th May 2019, 6:21 PM
eMBee
eMBee - avatar
5 Answers
+ 11
var x = 111; for(var i = 0; i < 5; ++i) { x += 2; console.log(x); x += 4; console.log(x); }
20th May 2019, 6:27 PM
Anna
Anna - avatar
+ 7
Anna, why is it that the code does not create an infinite loop, thus stopping at some certain number
21st May 2019, 7:14 AM
eMBee
eMBee - avatar
+ 4
var x = 111 for (var i = 0; i < 5; i++) { x += 2 document.write(x) // or console.log(x) document.write("<br/>") x += 4 document.write(x) document.write("<br/>") }
20th May 2019, 6:35 PM
PacoB
PacoB - avatar
+ 4
Wow, thanks a million Anna and PacoB, I hope to be as brilliant as you guys very soon
20th May 2019, 6:41 PM
eMBee
eMBee - avatar
+ 3
The code from Anna stops when i == 5 making thr statement in the middle ( i<5) false
22nd May 2019, 3:29 AM
Radu Baloi
Radu Baloi - avatar