Strings Hw

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

Code Runner Challenge

Create strings and perform various operations on them

View IPYNB Source
%%js
// CODE_RUNNER: Create strings and perform various operations on them 

/*
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
- And use string interpolation
*/

const str1 = "Hello";
const str2 = "World";
const str3 = "JavaScript";

console.log(`Length of "${str1}": ${str1.length}`);
console.log(`Length of "${str2}": ${str2.length}`);
console.log(`Length of "${str3}": ${str3.length}`);

console.log(`First and last character of "${str1}": ${str1[0]} and ${str1[str1.length - 1]}`);
console.log(`First and last character of "${str2}": ${str2[0]} and ${str2[str2.length - 1]}`);
console.log(`First and last character of "${str3}": ${str3[0]} and ${str3[str3.length - 1]}`);

// i concatenate all three strings into a sentence
const sentence = str1 + " " + str2 + " " + str3 + "!";
console.log(`Concatenated sentence: ${sentence}`);
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Course Timeline