Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed JavaScript Basics!
You have completed JavaScript Basics!
Preview
This video covers one solution to the "Variables and Strings" challenge.
"Variables and Strings" Challenge Solution
// 1. Declare variables and capture input.
const adjective = prompt('Please type an adjective.');
const verb = prompt('Please type a verb.');
const noun = prompt('Please type a noun.');
// 2. Combine the input with other words to create a story.
const sentence = `<p>There once was a ${adjective} programmer who wanted to use JavaScript to ${verb} the ${noun}.</p>`;
// 3. Display the story as a <p> inside the <main> element.
document.querySelector('main').innerHTML = sentence;
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Now, let me show you my solution,
0:00
which you can reference in the teacher's
notes and project files with this video.
0:00
Remember, I suggested breaking down
the program into small, testable steps, so
0:04
I'm not going to try to write
the entire program all at once.
0:08
In fact,
0:12
I'm going to start at the end with my
complete sentence as a paragraph element.
0:12
Between the <p> tags, I'll type,
0:19
There once was a [adjective] programmer
0:23
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up