Module 1 - String Methods 1 Flashcards
1
Q
Write a function called “getFullName”. Given a first and a last name, “getFullName” returns a single string with the given first and last names separated by a single space.
A
function getFullName(firstName, lastName) {
return firstName + “ “ + lastName;
}
2
Q
Write a function called “getLengthOfWord”. Given a word, “getLengthOfWord” returns the length of the given word.
A
function getLengthOfWord(word) {
return word.length;
}
3
Q
Write a function called “getLengthOfTwoWords”. Given 2 words, “getLengthOfTwoWords” returns the sum of their lengths.
A
function getLengthOfTwoWords(word1, word2) {
return word1.length + word2.length;
}