Skip to content

Instantly share code, notes, and snippets.

@dashcraft
Created January 30, 2017 00:19
Show Gist options
  • Save dashcraft/1e1a50ede7bd754610201f94183c5189 to your computer and use it in GitHub Desktop.
Save dashcraft/1e1a50ede7bd754610201f94183c5189 to your computer and use it in GitHub Desktop.
Free code camp part 4, rounding out javascript
const readline = require('readline');
const mike = readline.createInterface({
input: process.stdin,
output: process.stdout
});
// var person = function(personName,personAge){
// let name = personName;
// let age = personAge;
// let privatewhatever = 'oi';
// let obj = {
// name:name,
// age:age,
// checkAge:function(age){
// if(age){
// //do something
// }
// }
// }
// return obj;
// }
mike.question("What's you're name? ", function(answer) {
// TODO: Log the answer in a database
var personName=checkStringAnswer(answer);
mike.question('How old are you?', function(answer){
var age =checkIntAnswer(answer);
makePerson(personName,age);
})
});
function checkIntAnswer(answer){
var age=parseInt(answer)
if(!isNaN(age)){
if(typeof age == "number"){
if(age >65){
console.log('You qualify for medicare...maybe');
}
else{
console.log('Sorry bro, you gotta private insurance...$$$');
}
} return age;
}
else{
console.log("That wasn't a number!!!!");
mike.close();
}
}
function checkStringAnswer(answer){
var name = answer;
if(typeof answer == "string"){
answer = answer.toUpperCase();
if(answer == "DANIEL"){
console.log('Well, i thought you were cool but...');
}
else{
console.log("OIIII "+answer+" ?");
}
return name;
}
}
function makePerson(name,age){
if(name && age){
let customer = {
name:name,
age:age
};
console.log("Here is what we've gathered, \n Your name is "+person.name+' and you are '+person.age+' years old, sorry.');
}
else{
console.log('never mind');
mike.close();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment