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

// Your code here:
// Three strings of varying lengths
let str1 = "JavaScript";
let str2 = "is";
let str3 = "awesome!";

// Find and 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);

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

// Concatenate all three strings into a sentence
let sentence = str1 + " " + str2 + " " + str3;
console.log("Sentence:", sentence);
<IPython.core.display.Javascript object>

Course Timeline