+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)

5/20/2019 6:21:49 PM

Mofey

5 Answers

New Answer

+11

var x = 111; for(var i = 0; i < 5; ++i) { x += 2; console.log(x); x += 4; console.log(x); }

+7

Anna, why is it that the code does not create an infinite loop, thus stopping at some certain number

+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/>") }

+4

Wow, thanks a million Anna and PacoB, I hope to be as brilliant as you guys very soon

+3

The code from Anna stops when i == 5 making thr statement in the middle ( i<5) false