// Grab values from the submitted form in the URL const words = new URLSearchParams(window.location.search); // Cleans up and capitalizes the names of the animals function cleanAndCap (str){ if(!str) return null let temp = str.trim() return temp[0].toUpperCase() + temp.substring(1) } // Assigning the variables with values used in the story const firstAnimal= cleanAndCap(words.get('animal-1')); const secondAnimal = cleanAndCap(words.get('animal-2')); const answer = cleanAndCap(words.get('answer')); const conjunction = answer === 'Yes' ? 'and' : 'but'; const speed = words.get('speed'); const adj1 = words.get('adj-1'); const thirdAnimal = cleanAndCap(words.get('animal-3')); const quote = words.get('quote'); const verb1 = words.get('verb-1'); const num1 = words.get('num-1'); const message = words.get('message'); // The string containing HTML and text which will populate the story.html page const story = `

A ${firstAnimal} was making fun of the ${secondAnimal} one day for being so slow.

"Do you ever get anywhere?" he asked with a mocking laugh.

"${answer}," replied the ${secondAnimal}, "${conjunction} I get there ${speed} than you think. I'll run you a race and prove it."

The ${firstAnimal} was much ${adj1} at the idea of running a race with the ${secondAnimal}, but for the fun of the thing he agreed. So the ${thirdAnimal}, who had consented to act as judge, marked the distance yelled, "${quote}".

The ${firstAnimal} was soon far out of sight, and to make the ${secondAnimal} feel very deeply how ridiculous it was for him to try a race with a ${firstAnimal}, he went off the course to practice ${verb1} for ${num1} hours until the ${secondAnimal} should catch up.

The ${secondAnimal} meanwhile kept going slowly but steadily, and, after a time, passed the place where the ${firstAnimal} was ${verb1}. The ${firstAnimal} was so caught up in ${verb1}; and when at last he did stop, the ${secondAnimal} was near the goal. The ${firstAnimal} now ran his swiftest, but he could not overtake the ${secondAnimal} in time.

`; // Grabbing the title element const title = document.getElementById('title'); // Populating the title element with text title.innerHTML = `The ${firstAnimal} And The ${secondAnimal}`; // Grabbing the story element const storyEl = document.getElementById('story'); // Populating the story element with the value of the story variable storyEl.innerHTML = story; // Grabbing the moral-message element const moralMessage = document.getElementById('moral-message'); // Populating the moral-message element with text moralMessage.innerHTML = `"${message}"`;