Javascript Bytes (5): First letter of name

Let’s check to see if the first letter of the string is “S” or “s”, then control the flow of the function accordingly.

 

function doYouPlayTheTheremin(name) {
var nameArray = name.split(“”);

for (var i = 0; i < nameArray.length; i++) {
if (nameArray[i] === “S” || nameArray[i] === “s”) {

return name + ” plays the Theremin!”;

} else {

return name + ” does not play the Theremin!”;

}

}

return nameArray;

}

console.log(doYouPlayTheTheremin(“Senny”));

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s