write a poem in javascript

Writing a poem in JavaScript involves using string manipulation, variables, loops, and functions to create a formatted block of text. Here is an example of how you can achieve this:

index.tsx
// Define variables for the poem
const adjective = "beautiful";
const noun = "flower";
const verb = "dance";

// Define function to capitalize the first letter of a string
function capitalizeFirstLetter(string) {
  return string.charAt(0).toUpperCase() + string.slice(1);
}

// Define the lines of the poem in an array
const poem = [
  `${capitalizeFirstLetter(noun)}, oh ${adjective} ${noun}!`,
  `To see you ${verb} under the ${adjective} sun.`,
  `Your petals ${verb} with such ${adjective} grace,`,
  `A sight that time cannot erase.`,
  `With every ${verb}, you tell a story,`,
  `Of life, love, and all its glory.`,
  `How ${adjective} and ${adjective} you are,`,
  `My heart is filled with joy, oh ${noun} so far.`
];

// Loop through the poem array and print out each line
for(let i = 0; i < poem.length; i++) {
  console.log(poem[i]);
}
846 chars
27 lines

This code defines the variables for the poem's content, a function to capitalize the first letter of a string, and an array of the poem's lines. It uses a for loop to iterate over the poem array and prints out each line of the poem using the console.log() method. You can modify the variables and poem lines to create your own unique poem in JavaScript.

gistlibby LogSnag