1 (4 pts.). You are provided at the assignment site the HTML document prob2.html
ID: 3605960 • Letter: 1
Question
1 (4 pts.). You are provided at the assignment site the HTML document prob2.html, which references the JavaScript file prob2.js (which you write) and calls function go () when the body finishes loading. File prob2.js contains only the definition of go . The content of the body of the HTML document consists only of the following div element. the books are to be sent to Bob, the CDs are to be sent to Mike, and the iPad is to be sent to Ed Function go prompts for a name to replace all three names of people (Bob', 'Mike', and 'Ed') in the div content, as shown in the following screenshot. the books are to be sent to Bob, the CDs are to be sent to Mike, and the iPad is to be sent to Ed. The name to replace the crrent names, Cancel if none OK Cancel When the user enters a name and clicks OK, go invokes the replace ) method of the string content of the innerHTML property of the div object with a regular expression matching the three names (and nothing else); the second argument of the call to replace ) is the string entered at the prompt. The string returned by replace is used as the new value of the innerHTML property of the div object. For example, if the user enters ‘AI, then the rendering of the page becomes as follows the books are to be sent to Al, the CDs are to be sent to Al, and the iPad is to be sent to Al This is mostly an exercise in forming a regular expression that matches all and only the persons' names. Note that a name must be bordered at front and back by non-word characters.Explanation / Answer
<p id="name"></p>
<script>
function go()
{
var replace;
var word=prompt("the name to replace the current names,cancel if none","Bob","Mike","Ed");
if(word==null || word==" "){
replace="cancel the names";
}
else{
replace="the books are to be sent to" + word + "the CDs are to be sent to" + word + "and the iPad is to be sent to" + word + ;
}
document.getElementById("name").innerHTML=word;
}
</script>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.