Skip to content

Instantly share code, notes, and snippets.

Created December 1, 2015 03:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/f8466cf498c90350215d to your computer and use it in GitHub Desktop.
Save anonymous/f8466cf498c90350215d to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/dbess1 's solution for Bonfire: Confirm the Ending
// 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");
@dbess1
Copy link

dbess1 commented Dec 1, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment