Strings Lesson

A string is a text value surrounded by quotes. Strings are used for names, messages, labels, file paths, button text, and data that should be treated as words instead of numbers. JavaScript can join strings together with the plus operator or with template literals. Strings also have useful methods for changing case, removing extra spaces, and checking whether certain text appears. User text is often messy. A name might have extra spaces before or after it, so the program should clean it before building a message.

Code Runner Challenge

Strings Lesson

View IPYNB Source
%%js

// CODE_RUNNER: Strings Lesson

let playerName = "  Nova  ";
let cleanName = playerName.trim();
let message = "Welcome, " + cleanName + "!";

console.log(message);
console.log("Name length: " + cleanName.length);
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...