MCQ Single Best Answer Easy

QWhat would the following JavaScript code produce?

<button onclick="myFunction()">Try it</button>
<p id="demo">one</p>
<script>
function myFunction() 
{
   var str = document.getElementById("demo").innerHTML; 
   var txt = str.replace("one","two");
   document.getElementById("demo").innerHTML = txt;
}
</script>

ID: #5134 Javascript DOM & Event Handling MCQ 122 views
Question Info
#5134Q ID
EasyDifficulty
Javascript DOM & Event Handling MCQTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A one
  • B two
  • C error
  • D undefined
Correct Answer: Option B

Explanation

With the help of a given value, the replace function replaces string data.
The value of the data in the paragraph is altered using the innerHtml function.

Share This Question

Challenge a friend or share with your study group.