Study the code given below: <HTML> <HEAD> <SCRIPT LANGUAGE = "JavaScript">…

2017

Study the code given below: <HTML> <HEAD> <SCRIPT LANGUAGE = "JavaScript"> function start () { alert ("Event Occured") } </SCRIPT></HEAD> </BODY onLoad = "Start()"> <h1> Guess the event </H1> </BODY></HTML> How many times will the function Start () be called ?

  1. A.

    Once every time the system starts.

  2. B.

    Once every time the web page is refreshed.

  3. C.

    Only once when the window is opened.

  4. D.

    Will not be called as the event handler is wrong.

Attempted by 192 students.

Show answer & explanation

Correct answer: D

Answer: The function will not be called (0 times).

Reason: The onload attribute in the HTML calls Start(), but the JavaScript defines a function named start() with a lowercase s. JavaScript is case-sensitive, so Start() is undefined and the defined function is never invoked.

  • Primary issue: function name mismatch due to case sensitivity (Start vs start).

  • Secondary HTML issue: the code shows a misplaced closing </BODY> before the body with the onload attribute; the body tag should be properly opened as <body onload="start()">.

  • If you fix the call to match the defined function (for example, change the onload to call start()), the function will run once each time the page loads or is refreshed.

Suggested corrected HTML (described): Use a proper body tag and match the function name exactly, for example change the body start to body onload="start()" so the defined function start() is invoked once on page load.

Explore the full course: Up Lt Grade Assistant Teacher 2025