From a7f41a502efa594d21e0813b1e1488d3c29f27db Mon Sep 17 00:00:00 2001 From: chabuuuu Date: Thu, 15 Feb 2024 21:50:32 +0700 Subject: [PATCH] add js and ts code for aare-you-ok algo --- AreYouOk/AreYouOk.js | 37 +++++++++++++++++++++++++++++++++++++ AreYouOk/AreYouOk.ts | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 AreYouOk/AreYouOk.js create mode 100644 AreYouOk/AreYouOk.ts diff --git a/AreYouOk/AreYouOk.js b/AreYouOk/AreYouOk.js new file mode 100644 index 00000000..95a7be57 --- /dev/null +++ b/AreYouOk/AreYouOk.js @@ -0,0 +1,37 @@ +var readlineSync = require('readline-sync'); + +async function main () { + console.log("Oh, hey there, are u ok buddy?"); + let answer = "" + do { + answer = readlineSync.question(); + if(answer != 'y' && answer != 'n'){ + invalidAnswer(); + } + } while ((answer !== 'y') && (answer !== 'n')); + if (answer == 'n') { + console.log("You're definitely not ok.\n"); + console.log("Go there right now, you don't know what you're missing\n"); + }else if (answer == 'y'){ + console.log("Oh! Nice\n"); + console.log("Aren't they cute?\n"); + do { + answer = readlineSync.question(); + if(answer != 'y' && answer != 'n'){ + invalidAnswer(); + } + } while (answer != 'y' && answer != 'n'); + if (answer == 'n') { + console.log("You're definitely not ok.\n"); + } + else if(answer == 'y') { + console.log(":D\n"); + console.log("Well, everything actually seens ok with you\n"); + } + } +} +main() + +function invalidAnswer() { + console.log("Oh, I didn't understand you :(\nsay 'y' for yes or 'n' for no\n"); +} diff --git a/AreYouOk/AreYouOk.ts b/AreYouOk/AreYouOk.ts new file mode 100644 index 00000000..95a7be57 --- /dev/null +++ b/AreYouOk/AreYouOk.ts @@ -0,0 +1,37 @@ +var readlineSync = require('readline-sync'); + +async function main () { + console.log("Oh, hey there, are u ok buddy?"); + let answer = "" + do { + answer = readlineSync.question(); + if(answer != 'y' && answer != 'n'){ + invalidAnswer(); + } + } while ((answer !== 'y') && (answer !== 'n')); + if (answer == 'n') { + console.log("You're definitely not ok.\n"); + console.log("Go there right now, you don't know what you're missing\n"); + }else if (answer == 'y'){ + console.log("Oh! Nice\n"); + console.log("Aren't they cute?\n"); + do { + answer = readlineSync.question(); + if(answer != 'y' && answer != 'n'){ + invalidAnswer(); + } + } while (answer != 'y' && answer != 'n'); + if (answer == 'n') { + console.log("You're definitely not ok.\n"); + } + else if(answer == 'y') { + console.log(":D\n"); + console.log("Well, everything actually seens ok with you\n"); + } + } +} +main() + +function invalidAnswer() { + console.log("Oh, I didn't understand you :(\nsay 'y' for yes or 'n' for no\n"); +}