Question: Assignment: Simple Sentence Generator Objective: To practice using arrays and loops in JavaScript by creating a simple sentence generator. Instructions: Create an array called 'words'
Assignment: Simple Sentence Generator
Objective: To practice using arrays and loops in JavaScript by creating a simple sentence generator.
Instructions:
Create an array called 'words' that contains four words: "I", "like", to "code". You can modify this array to contain any words you like, but it should have at least four words.
Write a function called generateSentence: This function should use a for loop to iterate over the words array.
Inside the function, create a local variable called sentence that will be used to store the constructed sentence.
Create a loop that cycles through the array and adds concatenates each word followed by a space.
The array contents, I "like", to "code" should be processed into a single string, "I like to code".
The concatenated sentence should be stored in the sentence.variable you created.
Finally, use the innerHTML property to output the generated sentence to
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
