Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Javascript and Typescript code for "AreYouOk" Algorithms #1332

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions AreYouOk/AreYouOk.js
Original file line number Diff line number Diff line change
@@ -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");
}
37 changes: 37 additions & 0 deletions AreYouOk/AreYouOk.ts
Original file line number Diff line number Diff line change
@@ -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");
}