diff options
| author | Hyder <hyder@hyderhadi.xyz> | 2025-08-25 19:43:05 +0300 |
|---|---|---|
| committer | Hyder <hyder@hyderhadi.xyz> | 2025-08-25 19:43:05 +0300 |
| commit | a6d50f9a2a5dc022fb013bae003e7dbbe9413b1c (patch) | |
| tree | 0b8c16d63e61bc788355034ba00e51a8086c63ee /NGG/main.js | |
| parent | b4c6db0fc67d2d3f85891b0eca767bd0fa063379 (diff) | |
Im trying to learn JS, so THIS
Diffstat (limited to 'NGG/main.js')
| -rw-r--r-- | NGG/main.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/NGG/main.js b/NGG/main.js new file mode 100644 index 0000000..555812a --- /dev/null +++ b/NGG/main.js @@ -0,0 +1,38 @@ +const inputFunc = require('./inputfunc'); + +function numberGuessingGame(solution, range) { + if (solution == range) { + console.log("Correct guess!, Hurray đ"); + return 0; + } + else if (solution < range) { + console.log("Low guess đ"); + } + else if (solution > range) { + console.log("High guess đ
"); + } + else { + console.log("Wrong input âšī¸"); + } +} + +(async () => { + const range = Math.floor(Math.random() * (20 - 1 + 1) + 1); + let attempts = 0; + console.log("Guess the number? range is (1 to 20) (type 0 to Quit)\n"); + while (true) { + let solution = await inputFunc.input("") + let num = parseInt(solution, 10); + if (num === 0) { + console.log("đ¤đ¤đ¤"); + break; + } + if (numberGuessingGame(solution, range) == 0) { + attempts++; + console.log("Attempts: " + attempts); + break; + } + attempts++; + console.log("Attempts: " + attempts); + } +})();
\ No newline at end of file |
