Created
December 1, 2015 03:07
-
-
Save anonymous/f8466cf498c90350215d to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/dbess1 's solution for Bonfire: Confirm the Ending
This file contains 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
// Bonfire: Confirm the Ending | |
// Author: @dbess1 | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-confirm-the-ending | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function end(str, target) { | |
//I used a conditional to check if str (string) has the requested ending letter or word | |
//The target is the requested letter or word which is being called below | |
if(str.substr(-target.length) == target){ | |
return true; | |
} | |
else if(str.substr(-1) !== target){ //return false if it's not the requested letter or word | |
return false; | |
} | |
} | |
//This function named end is being called with arguments for str and target | |
end("Bastian", "n"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for the else if statement I could have wrote:
else if(str.substr(-target) !== target){
return false;
}
That might have been more consistent with the previous if statement.