Basic Knowledge - Exercise 2
Question 1: Make a Welcome Line Completed
Return "Welcome, " followed by the name and an exclamation mark.
Expected output: "Welcome, Sam!" (print this with console.log)
function makeWelcomeLine(name) {
// Write your solution here
}
console.log(makeWelcomeLine("Sam"));function makeWelcomeLine(name) {
return "Welcome, " + name + "!";
}
console.log(makeWelcomeLine("Sam"));Question 2: Count a Word's Characters Completed
Return the length of the supplied ASCII word.
Expected output: 6 (print this with console.log)
function countWordCharacters(word) {
// Write your solution here
}
console.log(countWordCharacters("planet"));function countWordCharacters(word) {
return word.length;
}
console.log(countWordCharacters("planet"));Question 3: Read the First Letter Completed
Return the first character of a non-empty string.
Expected output: "h" (print this with console.log)
function readFirstLetter(text) {
// Write your solution here
}
console.log(readFirstLetter("hello"));function readFirstLetter(text) {
return text[0];
}
console.log(readFirstLetter("hello"));Question 4: Read the Last Letter Completed
Return the last character of a non-empty string.
Expected output: "r" (print this with console.log)
function readLastLetter(text) {
// Write your solution here
}
console.log(readLastLetter("river"));function readLastLetter(text) {
return text[text.length - 1];
}
console.log(readLastLetter("river"));Question 5: Clean a Username Completed
Remove whitespace from the beginning and end of the supplied username.
Expected output: "sunny" (print this with console.log)
function trimUsername(username) {
// Write your solution here
}
console.log(trimUsername(" sunny "));function trimUsername(username) {
return username.trim();
}
console.log(trimUsername(" sunny "));Question 6: Create an Uppercase Label Completed
Return the supplied label in uppercase.
Expected output: "BOOKS" (print this with console.log)
function uppercaseShelfLabel(label) {
// Write your solution here
}
console.log(uppercaseShelfLabel("books"));function uppercaseShelfLabel(label) {
return label.toUpperCase();
}
console.log(uppercaseShelfLabel("books"));Question 7: Create a Lowercase Tag Completed
Return the supplied tag in lowercase.
Expected output: "javascript" (print this with console.log)
function lowercaseSearchTag(tag) {
// Write your solution here
}
console.log(lowercaseSearchTag("JAVASCRIPT"));function lowercaseSearchTag(tag) {
return tag.toLowerCase();
}
console.log(lowercaseSearchTag("JAVASCRIPT"));Question 8: Join Address Parts Completed
Join the street and city using a comma followed by one space.
Expected output: "Oak Street, Leeds" (print this with console.log)
function joinAddressParts(street, city) {
// Write your solution here
}
console.log(joinAddressParts("Oak Street", "Leeds"));function joinAddressParts(street, city) {
return street + ", " + city;
}
console.log(joinAddressParts("Oak Street", "Leeds"));Question 9: Repeat a Reminder Completed
Return the supplied word repeated the given non-negative integer number of times, with no separator.
Expected output: "gogogo" (print this with console.log)
function repeatReminderWord(word, count) {
// Write your solution here
}
console.log(repeatReminderWord("go", 3));function repeatReminderWord(word, count) {
return word.repeat(count);
}
console.log(repeatReminderWord("go", 3));Question 10: Build an Email Subject Completed
Return "Order " followed by the order number and " shipped".
Expected output: "Order 42 shipped" (print this with console.log)
function orderShippedSubject(number) {
// Write your solution here
}
console.log(orderShippedSubject(42));function orderShippedSubject(number) {
return "Order " + number + " shipped";
}
console.log(orderShippedSubject(42));