Quizes & Games

Javascript Quiz

The test contains 20 questions and it's not official, it's just a nice way to see how much you know, or don't know, about Javascript.

1.

How to write an IF statement for executing some code if "i" is NOT equal to 5?

if i =! 5 then
if (i != 5)
if (i <> 5)
if i <> 5

2.

Where is the correct place to insert a JavaScript?

Both the <head> section and the <body> section are correct
The <body> section
The <head> section
Before <html>

3.

How do you call a function named "myFunction"?

call myFunction()
call function myFunction()
myFunction()
myFunction

4.

How to write an IF statement in JavaScript?

if i == 5 then
if (i == 5)
if i = 5
if i = 5 then

5.

How does a WHILE loop start?

while (i <= 10)
while i = 1 to 10
while (i <= 10; i++)
while (i is 10)

6.

What is the correct JavaScript syntax to change the content of this html element <p id="demo">This is a demonstration.</p>

document.getElementById("demo").innerHTML = "Hello World!";
document.getElement("p").innerHTML = "Hello World!";
document.getElementByName("p").innerHTML = "Hello World!";
#demo.innerHTML = "Hello World!";

7.

How can you detect the client's browser name?

navigator.browsername
browser.name
navigator.appName
client.navName

8.

The external JavaScript file must contain the <script> tag.

Neither True nor False
True
False
Sometimes

9.

How do you create a function in JavaScript?

function = myFunction()
function:myFunction()
function ()
function myFunction()

10.

How does a FOR loop start?

for (i <= 5; i++)
for (i = 0; i <= 5; i++)
for (i = 0; i <= 5)
for i = 1 to 5

11.

How do you round the number 7.25, to the nearest integer?

rnd(7.25)
round(7.25)
Math.round(7.25)
Math.rnd(7.25)

12.

Inside which HTML element do we put the JavaScript?

<javascript>
<js>
<script>
<scripting>

13.

What is the correct syntax for referring to an external script called "xxx.js"?

<script name="xxx.js">
<script link="xxx.js">
<script src="xxx.js">
<script href="xxx.js">

14.

How can you add a comment in a JavaScript?

// This is a comment-->
//This is a comment
<!--This is a comment-->
'This is a comment

15.

What is the correct way to write a JavaScript array?

var colors = (1:"red", 2:"green", 3:"blue")
var colors = "red", "green", "blue"
var colors = ["red", "green", "blue"]
var colors = 1 = ("red"), 2 = ("green"), 3 = ("blue")

16.

How do you find the number with the highest value of x and y?

Math.max(x, y)
Math.ceil(x, y)
ceil(x, y)
top(x, y)

17.

How do you write "Hello World" in an alert box?

msgBox("Hello World");
alert("Hello World");
msg("Hello World");
alertBox("Hello World");

18.

What is the correct JavaScript syntax for opening a new window called "w2" ?

w2 = window.new("http://www.w3schools.com");
w2 = window("http://www.w3schools.com");
w2 = open("http://www.w3schools.com");
w2 = window.open("http://www.w3schools.com");