Task
Your client would like a chat-back program that repeats whatever the user says. The program should open with a line that says
“Say something to Polly the Parrot”
Polly the Parrot should then repeat what the user says, along with some Squawks!
Polly Parrot: *SQUAWK* hello *SQUAAAWK*
Solution
Say something to Polly the Parrot
Avast, matey! Ya better write some text, ‘fore ya walk tha plank!
Notice that this example uses an ‘event listener’ on the button inside the javascript window load instead of onClick inline code on the button.
Code
| // store the user input in a function and run onclick | |
| function userPrompt() { | |
| //get user input | |
| var userInput = prompt(“Enter yer text here, ya scurvy dawg: “); | |
| //display user input | |
| document.getElementById(“display-user-input”).innerHTML = “<br />Polly says:<hr /><br /> *SQUAWK* ” + “<h1>” + userInput + “</h1>” + ” *SQUAAAWK*”; | |
| } |
<button onclick=”userPrompt()”>Enter some Text</button>


