Preview

07 - Adding Javascript functionality

 1. JavaScript is the programming language of HTML and the Web. It helps make web pages _____________
Another way of saying this is that JavaScript programs the behaviour of web pages.

  busy

  interactive

  cluttered (full of various objects)

  static (still - and not moving)

 2. In HTML, JavaScript code must be inserted between ____________
1. <script> and </script> tags.

2. <java> and </java> tags.

3. <javascript> and </javascript> tags.

4. <js> and </js> tags

  Option 3

  Option 1

  Option 4

  Option 2

 3. A JavaScript function is a block of JavaScript code, that can be executed when "called" for.
For example, a function can be called when an event occurs, like when the user clicks a button.

  FALSE

  TRUE

 4. Read the following list about where to place a Javascript script. Which statement is true>
Where to place JavaScript in an HTML page?
===========================================

You can place any number of scripts in an HTML document.

1. Scripts can be placed in the <body> section of an HTML page

2. Scripts can be placed in the <head> section of an HTML page 

3. Scripts can be placed in either the <body> or <head> section of an HTML page

4. None of the above. Scripts can only be placed after the last closing </HTML> tag.

  Option 2

  Option 1

  Option 4

  Option 3

 5. Have a look at the code below. When you click the 'Try it' button, what will happen?
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction() {
    document.getElementById("demo").innerHTML = "I just love HTML";
}
</script>
</head>

<body>

<h2>JavaScript in Head</h2>

<p id="demo">A Paragraph.</p>

<button type="button" onclick="myFunction()">Try it</button>

</body>
</html> 

  The button will change into text which says "I just love HTML"

  The paragraph "A Paragraph" will change to "I just love HTML"

  The paragraph "A Paragraph" will be deleted from its position and put at the top of the page

  The button will go to a random link

 6. The number '11' should be displayed underneath 'My First Web page'. What is missing?
<!DOCTYPE html>
<html>
<body>
<h2>My First Web Page</h2>
<p id=""></p>
<script>
document.getElementById("demo").innerHTML = 5 + 6;
</script>
</body>
</html> 

  Line 5 is missing 'demo' in between the speech marks

  Line 6 should have an additional closing script tag.

  There is nothing missing - but it will display '5' to the screen, not 11.

  There is nothing missing. It will work fine.

 7. The following trinket shows an HTML page with embedded JavaScript to create a snake game. Where is the Javascript code?

  There is no JavaScript code - it is purely done in HTML

  In a separate file called 'snake.js' and it is called from index.html on line 23

  The JavaScript code is all contained in the index.html page

  The JavaScript code is all on line 23. One line is very powerful!

 8. JavaScript is the same language as Java.

  TRUE

  FALSE

 9. Here is another example of a JavaScript powered game. The JavaScript is in an _________ file.

  secure

  internal

  finalised

  external

 10. Read the excerpt below. Fill in the blanks for CSS.
JavaScript is one of the 3 languages all web developers must learn:

   1. HTML to define the content of web pages

   2. CSS to specify the ______________________

   3. JavaScript to program the behavior of web pages

  images used in web pages (It is not possible to use an image without CSS)

  layout of webpages

  names and saving types

  development of webpages (particularly the interactivity)