February 27, 2021

Introduction to JavaScript


Block 2 is largely concerned with teaching students how to program using JavaScript. This section provides a number of questions to test your knowledge of the subject. The answers can be accessed by left clicking whenever you see this graphic at the end of a question (switch off pop-up blocker if you have one enabled)

Letter A


The code I provide will often contain comments and appended notes as a means of explanation. I should also add that in some cases my code might not necessarily provide the only, or indeed the best solution to the question. However, the code will run under Netscape and this is something that you should practice on M150. JavaScript may run under MSIE, but it may fail under Netscape; I have certainly seen examples of this when marking end of course papers. For M150, you must ensure that your code correctly meets any requirements of a question by testing it on Netscape; this will be the browser that your tutor will use for testing TMA code.

Some of these questions are fairly demanding, particularly Q11, which to be honest is probably far more difficult than anything that you will face on M150.


  • I have followed the M150 practice of writing all HTML tags in uppercase, but I often revert to using lowercase in the questions on the following pages.
  • M150 uses a consistent HTML template for embedding JavaScript code. The code is placed between <SCRIPT></SCRIPT> tags in the head of a HTML document. However, it is possible to place the tags and JavaScript in other parts of a Web document.

    <SCRIPT LANGUAGE = "JavaScript">
       //On M150, JavaScript is placed here in the head of the document
  <!-- this is an HTML comment -->
      //However, JavaScript could be placed here in the body of the doc
      // or even here at the end

For consistency, please follow the M150 "house-style" and embed your code in the head of the document. For these exercises, you are not required to write the HTML template.

Next page » Strings













Up to top of page