Iteration
This page is under construction. Please come back later.
#!/usr/bin/env node; const Utils = require('./Utils'); const main = async () => { let max = 5; if (process.argv.length == 3) { max = Utils.stoiWithDefault(process.argv[2], 5); } for (let i = 0; i < max; ++i) { console.log("Hello, world!"); } } main().catch( e => { console.error(e) } );
Output
$ node Iteration1.js 5
Hello, world!
Hello, world!
Hello, world!
Hello, world!
Hello, world!
#!/usr/bin/env node; const main = async () => { for (let i = 10; i >= 1; --i) { console.log(i); } console.log("Blastoff!"); } main().catch( e => { console.error(e) } );
Output
$ node Iteration2.js
10
9
8
7
6
5
4
3
2
1
Blastoff!
#!/usr/bin/env node; const main = async () => { console.log("Even numbers up to 100..."); for (let i = 2; i <= 100; i += 2) { console.log(i); } } main().catch( e => { console.error(e) } );
Output
$ node Iteration3.js
Even numbers up to 100...
2
4
6
8
10
12
14
16
18
...
82
84
86
88
90
92
94
96
98
100
#!/usr/bin/env node; const main = async () => { console.log("Floating point numbers"); for (let d = 1.0; d < 2.01; d += 0.1) { console.log(d); } } main().catch( e => { console.error(e) } );
Output
$ node Iteration4.js
Floating point numbers
1
1.1
1.2000000000000002
1.3000000000000003
1.4000000000000004
1.5000000000000004
1.6000000000000005
1.7000000000000006
1.8000000000000007
1.9000000000000008
2.000000000000001
#!/usr/bin/env node; const main = async () => { console.log("Powers of 2 up to 256!"); for (let i = 1; i <= 256; i *= 2) { console.log(i); } } main().catch( e => { console.error(e) } );
Output
$ node Iteration5.js
Powers of 2 up to 256!
1
2
4
8
16
32
64
128
256
#!/usr/bin/env node; const main = async () => { let s = "Hello, world! 🥰🇺🇸"; for (let c of s) { console.log(c); } } main().catch( e => { console.error(e) } );
Output
$ node Iteration6.js
H
e
l
l
o
,
w
o
r
l
d
!
🥰
🇺
🇸
Iterators
javascriptQuestions
- {{Who's on first?}}
- {{Who's on second?}}
- {{Who's on third?}}
Projects
More ★'s indicate higher difficulty level.
- Amortization Table
- Amortization Table (Revisited)
- Blackboard
- Blackboard (Revisited)
- Character Types
- Compute π (Monte Carlo)
- Floating Point Error
- ISBN-10 Check
- License Plate Generator
- Multiplication Table
- Number Guessing Game
- Punchcard Message
- Random Floats
- Random Integers
- Supermarket Sale
- Supermarket Sale (Revisited)
- Temperature Table
- Unicode Test
References
- [[JavaScript Language Reference]], Mozilla Developer Network
- [[Mozilla Developer Network]]
- Download [[node.js]]
- [[w3schools.com]]