Sprint View

Strings

1 min read

Homework

Requirements:

  • Include three strings of varying lengths
  • Find the length of each string and print them
  • Find the first and last character of each string and print them
  • Concatenate all three strings into a sentence and print the result
%%js

// Three strings of different lengths
let str1 = "Cat";
let str2 = "Elephant";
let str3 = "Blueberry Pie";

// 1. Print the length of each string
console.log("Length of str1:", str1.length);
console.log("Length of str2:", str2.length);
console.log("Length of str3:", str3.length);

// 2. Print the first and last character of each string
console.log("First and last of str1:", str1[0], str1[str1.length - 1]);
console.log("First and last of str2:", str2[0], str2[str2.length - 1]);
console.log("First and last of str3:", str3[0], str3[str3.length - 1]);

// 3. Concatenate all three strings into a sentence
let sentence = str1 + ", " + str2 + ", and " + str3 + " are my strings.";
console.log(sentence);


<IPython.core.display.Javascript object>

Course Timeline