Created
September 17, 2022 17:25
-
-
Save motebaya/c5c07f153104d9008e39551f7c1b73e2 to your computer and use it in GitHub Desktop.
node js hello world for sample or test with oop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
file tester with node js oop | |
help from: | |
https://stackoverflow.com/questions/9071573/is-there-a-simple-way-to-make-a-random-selection-from-an-array-in-javascript-or | |
https://stackoverflow.com/questions/951021/what-is-the-javascript-version-of-sleep | |
https://stackoverflow.com/questions/18188083/javascript-oop-in-nodejs-how | |
*/ | |
class Tester { | |
constructor(text){ | |
this.text = text | |
this.colors = [ | |
"\x1b[1;31m", "\x1b[1;32m", "\x1b[1;33m", "\x1b[1;37m", | |
"\x1b[1;34m" | |
] | |
this.time = 10000 | |
} | |
async run(){ | |
for (var i of `[ ${this.text} ]\n`){ | |
var color = this.colors[Math.floor(Math.random() * this.colors.length)] | |
process.stdout.write( | |
`${color}${i}` | |
) | |
await new Promise(r => setTimeout(r, 100)); | |
} | |
} | |
} | |
(new Tester("Hello World")).run() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment