2.5 - "Strings"

Review

let answer = 0;

// Add 1+2+3+4+5+6+7+8+9+10

for (let index = 1; index <= 10; index++) {

 answer += index;

}

console.log(answer);  // 55


Mr. Squirrel's Joke of the Day

"Today I learned that if you turn a canoe over, you can wear it as a hat.


Because it's capsized!"

If today's lesson doesn't quite make sense, check out lessons 19 to 22 here.

Today's Lesson: "Strings"



Properties and Functions


It is very important to remember that "a" and "A" are considered different. "Hello" != "hello"


A property is a fact about that object or thing.

Strings have a very important property: length

let myString = "Hello World!";

console.log(myString.length);   // Prints 12 to the screen


A function - also known as a method - is something that an object can do or give or utilize to manipulate data or give a result.
Strings have lots of useful functions but the ones we might focus on are:


Extracting & Changing Characters

let text = "My name is Mr. Squirrel";
console.log(text.length);  // 23
console.log(text[1]);  // y
console.log(text[23]); // undefined


let longText = "Supercalifragilisticexpialidocious";

for (let letter = 0; letter < longText.length; letter++) {

 console.log(longText[letter]);

}


3.4 Task(s) / Homework