Created
February 24, 2017 19:04
-
-
Save chasen-bettinger/1461e6c47ee3a0d43d94c1af27580597 to your computer and use it in GitHub Desktop.
Compare the relationship between two variables
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
function getRelationship(x, y) { | |
if(x !== x) { | |
return "Can't compare relationships because " + x + " and undefined are not numbers"; | |
} | |
if (typeof x != 'number' || typeof y != 'number') { | |
if(arguments.length === 2) { | |
if(typeof x != 'number' && typeof y != 'number') { | |
return "Can't compare relationships because " + x + " and " + y + " are not numbers"; | |
} | |
else { | |
return "Can't compare relationships because " + x + " is not a number"; | |
} | |
} | |
else if (typeof x === 'number' && typeof y != 'number') { | |
return "Can't compare relationships because undefined is not a number"; | |
} | |
else { | |
return "Can't compare relationships because " + x + " and undefined are not numbers"; | |
} | |
} | |
//Can't compare relationships because [this value] and [that value] [is]/[are] not [a] number[s]. | |
if(x > y) { | |
return ">"; | |
} | |
else if (x < y) { | |
return "<"; | |
} | |
else { | |
return "="; | |
} | |
} | |
// Try logging these functions to test your code! | |
console.log(getRelationship(1,4)); | |
console.log(getRelationship(1,1)); | |
console.log(getRelationship("that",2)); | |
console.log(getRelationship("this"," something else")); | |
console.log(getRelationship(3)); | |
console.log(getRelationship("hi")); | |
console.log(getRelationship(NaN)); | |
console.log(getRelationship(NaN, undefined)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment