JS 2 Flashcards

1
Q

Which event occurs when the user clicks on an HTML element?

A

onclick

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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

A

if (i != 5)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you write “Hello World” in an alert box?

A

alert(“Hello World”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the correct way to write a JavaScript array?

A

var colors = [“red”, “green”, “blue”]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to insert a comment that has more than one line?

A

//This comment has……more than one line//
/This comment has…….more than one line/
<!--This comment has......more than one line-->

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the correct JavaScript syntax to change the content of the HTML element below?

<p>This is a demonstration.</p>

A

demo.innerHTML = “Hello World!”;

document.getElementByName(“p”).innerHTML = “Hello World!”;

document.getElement(“p”).innerHTML = “Hello World!”;

document.getElementById(“demo”).innerHTML = “Hello World!”;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How can you add a comment in a JavaScript?

A

<!--This is a comment-->

//This is a comment
‘This is a comment

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Which operator is used to assign a value to a variable?

A

*

-
x

How well did you know this?
1
Not at all
2
3
4
5
Perfectly