kata
Create a function which answers the question "Are you playing banjo?".
If your name starts with the letter "R" or lower case "r", you are playing banjo!
The function takes a name as its only argument, and returns one of the following strings:
name + " plays banjo"
name + " does not play banjo"
Names given are always valid strings.
my answer
function areYouPlayingBanjo(name) {
var nametext = name.slice(0,1);
if (nametext === "R" || nametext === "r" ) {
name = `${name} plays banjo`
} else {
name = `${name} does not play banjo`
}
return name ;
}
best answer
function areYouPlayingBanjo(name) {
return name + (name[0].toLowerCase() == 'r' ? ' plays' : ' does not play') + " banjo";
}