Multiple Choice Questions
Which of the following statements declares a variable named highScore?
Which of the following can be used to modify the text within a paragraph?
Which of the following for-loop declarations creates a loop that will execute 4 times?
Which of the following statements invokes a function named myFunction that has no parameters?
Which message will be displayed on the document when the following code is executed? var num = 40; if(num > 60) { document.write("zone 1"); } else if(num > 25) { document.write("zone 2"); } else{ document.write("zone 3"); }
Which of the following statements declares a (non-global) variable named myNum and assigns it a value of 24?
What is the result of the following statement? typeof 340.2
Which of the following keywords is used to define a function?
What will the value of x be when the following while loop stops executing? var x = 4; while(x > 0) { alert("Hello "); x--; }
Consider the code: var greeting = "Hello"; var contact = { firstName: "Jane", lastName: "Doe", age: 35 }; What line of code update the greeting variable to store the value "Hello Jane"?
typeof -34.7
typeof "390" What is the result of the this statement?
var x = 4; var y = 9; var z = x < y; What value is stored in the variable z above?
typeof "Hello, world"
JavaScript code is case sensitive.
typeof "-34.7"
Consider the following code: var book = { title: "Romeo and Juliet", authorFirstName: "William", authorLastName: "Shakespeare", publishDate: 1597 }; The code above creates a(n) ________ with the identifier book.
var x = 25; var y = 12; var z = x < y;What is the data type of the variable z above?
Which message will be displayed on the document when the following code is executed? var num = 24; if(num > 82) { document.write("zone 1"); } else if(num >= 43) { document.write("zone 2"); } else{ document.write("zone 3"); }
JavaScript is a(n) ________.
Which statement retrieves the element "d" from the array myArray? var myArray = ["a", "b", "c", "d", "e"];
JavaScript can only run in a browser (It cannot run in other environments).
Which JavaScript statement creates a new list item element and stores it in a new variable named listItem.
What output will be displayed on the document when the following loop completes? for(x = 0; x < 4; x++){ document.write(x + " "); }
var x = 25; var y = 12; var z = x < y;What value is stored in the variable z above?
Which alert message(s) will be displayed when the following code runs? var num = 42; if(num <= 30) { document.write("Alert message #1"); } else{ document.write("Alert message #2"); }
Which alert message(s) will be displayed when the following code runs? var num = 35; if(num <= 30) { document.write("Alert message #1"); } else{ document.write("Alert message #2"); }
Which of the following statement sets a function called myHandler to be called when myButton is clicked?
Which of the following statements invokes a function named myFunction that accepts a numeric parameter?
Consider the following code: var x = 2; var y = 6; var z = -3; Which of the following line of code will update the stored value of the variable y to 3?
Which of the following statement would return a collection of elements that have the class "special"?
Consider the following object: var book = { title: "Romeo and Juliet", author: "William Shakespeare", publishDate: 1597 }; Considering the book object above, which line of code will write the publish date of the book object to the browser console?
Which of the following statements declares a variable named score?
Which of the following statements calls a function, giveMeANumber, and passes the number 4 as a parameter?
A complete line of JavaScript code that can be executed by the computer is called a(n) ________.
Which of the following statements changes the href attribute of an element to "www.microsoft.com"?
Which statement creates an array named colors and stores 4 elements?
A ________ is a container that can store a value in your program that can be accessed or modified at a later point.
What causes a loop to be infinite?
Consider the variable: var greeting = "Hello"; greeting += "John";What value is stored in the greeting variable after the 2nd line of code?
How can a function return a value?
Which message will be displayed on the document when the following code is executed? var x = 3; var y = 8; if(x % 2 == 1 && y > 6) { document.write("This test passed" ); }else{ document.write("This test failed"); }
What value is stored in the variable x after the following lines of code are executed? var x = 9; var y = 3; var z = x%y;
Which of the following lines of code produces the value "William Shakespeare"?
Which JavaScript statement creates a new list item element and stores it in a new variable named listItem?
JavaScript was created by Google in 2005 for the Gmail application that needed more interactivity
Which of the following statements stores a value returned from a function?
What value is stored in the variable x after the following lines of code are executed? var x = 3; x*=2;
Which line of code creates a variable named language that holds that value "JavaScript"?
var x = 34; var y = 10; var z = x%y;What value is stored in the variable z after the following lines of code are executed?
Which of the following does not output information to the user via the webpage?
var language = "JavaScript"; The data type of the language variable above is:
Which of the following statements defines a function named increment that returns a value and defines a parameter?
Which of the following are used to create a variable and assign it a value?
Consider the following object: var book = { title: "Romeo and Juliet", author: "William Shakespeare", publishDate: 1597 }; Considering the book object above, author is a ________ of the book object.
var x = 4; var y = 9; var z = x < y; What is the data type of the variable z above?
JavaScript statements end with ________.
Which of these is a JavaScript array?
Consider the following code: var x = 2; var y = 6; var z = -3; What is the datatype of the variable **z**?
Which JavaScript statement uses the document object to get a list of all of the h1 elements on a page and stores the collection in a variable named headings.
JavaScript allows you to develop webpages that are ________. This means the webpage's content changes based on conditions and interactions.
What belongs immediately after the if keyword in an if statement, within the parentheses? if ( )
var myVar = "23"; What is the data type of the variable myVar?
Which message will be displayed on the document when the following code is executed? var x = 3; var y = 8; if(x < 5 && y > 6) { document.write("This test passed"); } else{ document.write("This test failed"); }
var mySection = document.getElementById("mySection"); var special = mySection.getElementsByClassName("special");What will the variable special contain after this code is executed?
A(n) ________ can hold a collection of named values, known as properties.
Which of the following statements changes the CSS background-color of an element to "green"?
In order to write JavaScript code that is embedded in an HTML file, your JavaScript code belongs ________.
Assume that a variable has been declared and initialized with the following statement: var count = 4;Which of the following statements updates the variable with the value 24?
Consider the following code: var book = { title: "Romeo and Juliet", authorFirstName: "William", authorLastName: "Shakespeare", publishDate: 1597 }; What line of code logs the value of the title property to the console?
Which statement retrieves the element with the value 32 from the array numbers? var numbers = [1, 3, 12, 42, 32, 4];
In JavaScript, in order to change the content of an HTML document or the CSS style of HTML elements, we use:
What is the primary role of JavaScript?
What is an infinite loop?
A JavaScript script will always be executed after the HTML page finishes loading.
A JavaScript variable that originally stored a number can later store a string value.