String Methods Flashcards
1
Q
Find the position of the character h in the string txt and assign it to a variable named pos.
var txt = “abcdefghijklm”;
A
let pos = txt.indexOf(“h”);
2
Q
Use the slice method to assign the word “bananas” to a variable named x.
var txt = “Go bananas!”;
A
let x = txt.slice(3 , 10);
3
Q
Use the correct String method to replace the word “Hello” with the word “Welcome”.
var txt = “Hello World”;
A
let = txt.replace(“Hello”, Welcome”);
4
Q
Convert the value of txt to upper case.
var txt = “Hello World”;
A
let = txt.toUpperCase();
5
Q
Convert the value of txt to lower case.
var txt = “Hello World”;
A
let = txt.toLowerCase();