Javascript

¡Supera tus tareas y exámenes ahora con Quizwiz!

3. Where is the correct place to insert a JavaScript? The <body> section Both the <head> section and the <body> section are correct The <head> section

Both the <head> section and the <body> section are correct

How does a FOR loop start? for i = 1 to 5 for (i = 0; i <= 5) for (i = 0; i <= 5; i++) for (i <= 5; i++)

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

Which is the syntax that will result in an error in extracting the value "16" from the object ? const Person={ fname:"Harry", lname:"Potter", age:16 } alert(Person.age); alert(Person["age"]); alert(Person[age]);

alert(Person[age]);

Which event occurs when the user clicks on an HTML element? onclick onmouseover onmouseclick onchange

onclick

How to write an IF statement in JavaScript? if (i == 5) if i == 5 then if i = 5 if i = 5 then

if (i == 5)

How do you call a function named "myFunction"? myFunction() call function myFunction() call myFunction()

myFunction()

How do you replace "green" with "yellow" in the array colors ["red", "blue", "green"] ? colors[2]="yellow"; colors[3]="yellow"; colors["green"]="yellow"; colors(2)="yellow";

colors[2]="yellow";

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

False

The shift method works on an array to insert elements at the beginning of the array False True

False

What is the output ? const myArray=[1,2,3,4,5,6]; console.log(myArray.push(7,8)); TypeError 8 7 Push does not take parameters.

8

What is the syntax for executing a function myFunc when the user clicks the button element ? <button onclick="myFunc">Click me!</button> <button onclick="myFunc()">Click me!</button> <button onclick=myFunc()>Click me!</button>

<button onclick="myFunc()">Click me!</button>

What is the output on the console when this command is run ? const i=10; console.log(i++); 11 10 TypeError

TypeError

How do you alert the name "John" from the object ? const Person={ fname:"John", lname:"Milton", age:40 } alert(Person.fname); alert(person.fname); alert(Person); alert(Person[0]);

alert(Person.fname);

Is JavaScript case-sensitive? No Yes

Yes

How do you write "Hello World" in an alert box? alertBox("Hello World"); alert("Hello World"); msgBox("Hello World"); msg("Hello World");

alert("Hello World");

How do you create a function in JavaScript? function = myFunction() function myFunction() function:myFunction()

function myFunction()

What is the correct JavaScript syntax for opening a new window called "w2" ? w2 = window.open("http://www.w3schools.com"); w2 = window.new("http://www.w3schools.com");

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

How does a WHILE loop start? while (i <= 10; i++) while (i <= 10) while i = 1 to 10

while (i <= 10)

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")

var colors = ["red", "green", "blue"]

How to insert a comment that has more than one line? /*This comment has more than one line*/ //This comment has more than one line// <!--This comment has more than one line-->

/*This comment has more than one line*/

What is the output ? let i=10; console.log(10%2); 5 0 20 100

0

JavaScript is the same as Java. True False

False

How can you detect the client's browser name? client.navName navigator.appName browser.name

navigator.appName

What is the value of typeof(23 + "Hello") ? string boolean TypeError number

string

How to write an IF statement for executing some code if "i" is NOT equal to 5? if (i != 5) if (i <> 5) if i =! 5 then if i <> 5

if (i != 5)

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

What is the output of line 7 ? 1.let count=1; 2.for (let i=0;i<=5;i++){ 3. let count=0; 4. console.log(count); 5. count++; 6.} 7. console.log(count); 1 0 5 4 6

1

What is the output on the console when this command is run ? console.log(Math.floor(Math.PI)+Math.ceil(Math.PI)+Math.round(Math.PI)); 10 11 9 12

10

What is the output on the console when this command is run ? let i=10; console.log(i++); 11 10 TypeError

10

What is the output on the console when this command is run ? let i=10; console.log(++i); 11 10 TypeError

11

How do you remove the last element of the array myArray ? myArray.pop() myArray.pop[-1] myArray.pop(myArray.length)

myArray.pop()

4. What is the correct syntax for referring to an external script called "xxx.js"? <script name="xxx.js"> <script src="xxx.js"> <script href="xxx.js">

<script src="xxx.js">

What is the output of below ? const myArray=[1,2,3,4,5,6]; myArray.splice(4,2,7,8,9); console.log(myArray); [ 1, 2, 3, 4, 7, 8, 9 ] [ 1, 2, 3, 4, 5,6,7, 8, 9 ] [4,2,7,8,9] [1,2,3,6,7,8,9]

[ 1, 2, 3, 4, 7, 8, 9 ]

What is the output of below ? const myArray=[1,2,3,4,5,6]; let myArray2=myArray.slice(2,-1); console.log(myArray2); [ 3, 4, 5 ] [ 2,3, 4, 5 ] [ 3, 4, 5 ,6] []

[ 3, 4, 5 ]

What is the output ? const myArray=[1,2,3,4,5,6]; myArray.shift(); console.log(myArray); 1 Syntax Error Type Error [2,3,4,5,6]

[2,3,4,5,6]

What will the following code return: Boolean(10 > 9) true false NaN

true

let str = "Apple, Banana, Kiwi"; let part = str.slice(7, 13); What is the value contained in part ? Banana Banana, Banana Banana,

Banana

let str = "Apple, Banana, Kiwi"; let part = str.substr(7); What is the value contained in part ? Banana, Kiwi Banana Apple, Apple

Banana, Kiwi

What is the correct syntax to change the background color of the div tag to red upon clicking it? <div onclick="this.style.backgroundColor='red'">some text in the div tag</div> <div onClick="this.style.backgroundColor='red'">some text in the div tag</div> <div onclick="this.style.backgroundColor="red"">some text in the div tag</div>

<div onclick="this.style.backgroundColor='red'">some text in the div tag</div>

1. Inside which HTML element do we put the JavaScript? <scripting> <script> <js> <javascript>

<script>

Which operator is used to assign a value to a variable? x = - *

=

How do you find the number with the highest value of x and y? ceil(x, y) Math.max(x, y) Math.ceil(x, y) top(x, y)

Math.max(x, y)

How do you round the number 7.25, to the nearest integer? rnd(7.25) Math.rnd(7.25) Math.round(7.25) round(7.25)

Math.round(7.25)

let x = "0"; switch (x) { case 0: text = "Off"; break; case 1: text = "On"; break; default: text = "No value found"; } What will the variable text contain at the end of the code block ? Off On No Value found Type Error

No Value found

Which is the incorrect syntax ? for(i=0;i<=5;i++) for(i=0;i<=5;) for(;i<=5;) None

None

How do you invoke the object's method ? const Person={ fname:"Harry", lname:"Potter", age:16, getFullName:function(){ return(Person.fname + " " + Person.lname); } } Person.getFullName(); Person.getFullName; Person.getfullname(); Person.getfullname;

Person.getFullName();

The "break" command is to come out of the for/while loop or switch statement True False

True

The "continue" statement breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration in the loop True False

True

2. What is the correct JavaScript syntax to change the content of the HTML element below? <p id="demo">This is a demonstration.</p> document.getElement("p").innerHTML = "Hello World!"; #demo.innerHTML = "Hello World!"; document.getElementByName("p").innerHTML = "Hello World!"; document.getElementById("demo").innerHTML = "Hello World!";

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

How do you determine the count of items in array myArray? myArray.count myArray.length array.count array.length

myArray.length

What is the value of typeof(null + "Hello") ? string boolean TypeError number

string

How do you declare a JavaScript variable? var carName; v carName; variable carName;

var carName;


Conjuntos de estudio relacionados

Econ Quiz chapter 4-5 Multiple Choice

View Set

Communication for Business Professionals final

View Set

US History Chapter 3 Reconstruction

View Set

MKGT 301: Exam 3 (chapters 10, 12, 13, 14)

View Set

Computer Programming exam Part 1

View Set

AP Psychology Personality Unit 10

View Set