JavaScript Quiz 1ΒΆ
The following Quiz is for me to assess what you have learned about JavaScript. Some questions have been repeated from the pretest and some are new. A couple are diabolical so take your time and think them through. It is a closed book quiz. You may not refer to any other page on the internet besides this one right here. You may not copy and paste code snippets into any kind of Javascript interpreter. This quiz is covered by the Luther College Honor Code, you may not cheat and you are expected to report anyone you see cheating.
Remember once you start you cannot leave the page or refresh the page. Doing so will cause the quiz to submit and you will be done.
- document.getElementById("demo").innerHTML = "Hello World!";
- #demo.innerHTML = "Hello World!";
- document.getElementByName("p").innerHTML = "Hello World!";
- document.getElement("p").innerHTML = "Hello World!";
- const carName = 10;
- var carName;
- let carName;
- carName = 10;
- ReferenceError: foo is not defeined
- ReferenceError: y is not defined
- NaN then 11
- 110 then 11
- 6
- 5
- 3
- ReferenceError: i is not defined
- 6
- 5
- 3
- ReferenceError: i is not defined
- Its an error
- 'a', 'b', 'c' - each on their own line
- 1, 2, 3 - each on their own line
- 0, 1, 2 - each on their own line
- Its an error
- 'a', 'b', 'c' - each on their own line
- 1, 2, 3 - each on their own line
- 0, 1, 2 - each on their own line
- Its an error
- 'a', 'b', 'c' - each on their own line
- 1, 2, 3 - each on their own line
- 0, 1, 2 - each on their own line
- Nothing
- 0
- 1
- some kind of error
jsquiz1-1: What is the correct JavaScript syntax to change the content of the HTML element below?
<p id="demo">This is a demonstration.</p>
jsquiz1-2: How do you declare a JavaScript variable with block scope?
jsquiz1-3: What is the output of the following?
"use strict"
var y = 100
foo()
function foo() {
let x = 10 + y;
var y
y = 1
let z = 10 + y
console.log(x)
console.log(z)
}
jsquiz1-4: What is the output of the following code snippet?
var sum = 0;
for(let i = 0; i < 3; i++) {
sum += i
}
let last = sum + i
console.log(last)
jsquiz1-5: What is the output of the following code snippet?
var sum = 0;
for(var i = 0; i < 3; i++) {
sum += i
}
let last = sum + i
console.log(last)
jsquiz1-6: What is the output of the following?
l = ['a', 'b', 'c']
for (var i of l) {
console.log(i)
}
jsquiz1-7: What is the output of the following?
l = ['a', 'b', 'c']
for (var i in l) {
console.log(i)
}
jsquiz1-8: What is the output of the following?
l = ['a', 'b', 'c']
for (let i=0; i < l.length; i++) {
console.log(l[i])
}
jsquiz1-9: what is the output of the following snippet of code?
let i = 0;
let sum = 0;
do {
sum = sum + i
console.log(sum)
i -= 1
} while( i > 0 )
Write a class called Rectangle that has a constructor and a method called area. The constructor should take two arguments length first then width. The area function should return the area of the rectangle.