Strings Homework
Strings Homework using Code Runner
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
// Create three strings of varying lengths
let string1 = "Hello";
let string2 = "JavaScript";
let string3 = "Programming";
// Find and print the length of each string
console.log("Lengths:");
console.log(`"${string1}" has length: ${string1.length}`);
console.log(`"${string2}" has length: ${string2.length}`);
console.log(`"${string3}" has length: ${string3.length}`);
// Find and print first and last character of each string
console.log("\nFirst and Last Characters:");
console.log(`"${string1}": first='${string1[0]}', last='${string1[string1.length-1]}'`);
console.log(`"${string2}": first='${string2[0]}', last='${string2[string2.length-1]}'`);
console.log(`"${string3}": first='${string3[0]}', last='${string3[string3.length-1]}'`);
// Concatenate all three strings into a sentence
let sentence = string1 + " " + string2 + " " + string3;
console.log("\nConcatenated sentence:");
console.log(sentence);
<IPython.core.display.Javascript object>