To select an answer for the multiple choice questions, put an
x
inside the square brackets ([ ]
) like this:- [ ] This is the answer!Pro tip: You might find it easier to read the assessment through VS Code's Markdown Preview. To view the preview for this document, open the Command Palette (Cmd+Shift-P or Ctrl+Shift-P) and run
Markdown: Open Preview to the Side
.
Which statement is true about JavaScript?
- A. JavaScript is case insensitive, so
true
is the same asTrue
. - B. JavaScript ignores whitespace characters like spaces and newline characters.
- C. JavaScript requires you to end all statements with a semicolon (
;
). - D. All of the above are true.
- E. None of the above are true.
Assume you've initialized a variable, sum
, like so:
let sum = 1;
Which of these lines of code will cause sum
to have a value of 2
? You can select more than one
answer.
- A.
sum++
- B.
sum += 1
- C.
sum = sum + 1
- D. All of the above
- E. Some of the above
What's the output of the program below?
const result = 1 < 100 || 'hello' === 'hi';
console.log(result);
- A.
true
- B.
false
- C.
undefined
- D. N/A because the code has an error
What's the output of the program below?
const word = '';
if (word) {
console.log('yay!');
} else {
console.log('no :(');
}
- A.
yay!
- B.
no :(
- C. An empty line
- D. N/A because the code has an error
The code below is incomplete. There's a blank space inside the for
loop:
const fruits = ['apple', 'berry', 'cherry'];
for (______) {
console.log(fruit);
}
Fill in the blank---select the code that will produce the following output:
apple
berry
cherry
- A.
const fruit in fruits
- B.
const fruit of fruits
- C.
let fruit = 0; fruit < fruits.length; fruit++
- D. None of the above
What will happen when we run the program below? If there's more than one option that seems correct, pick the one you think is most accurate.
function makeWordArray(phrase) {
return phrase.split(' ');
}
- A. Nothing happens because the program errors out.
- B. It defines a function called
makeWordArray
and convertsphrase
into an array of words. - C. It defines a function called
makeWordArray
and outputs a word array. - D. It defines a function called
makeWordArray
but nothing else happens.
Which statement best describes the error below?
console.log'hi';
// expected output:
// hi
- A. The code causes an error because there should be parentheses around
'hi'
. - B. The code causes an error because
console.log
isn't a function. - C. The code causes an error because the code will run but it won't output anything.
- D. There is no error; the code generates the expected output.
Which statement best describes the error below?
const fruits = ['apple', 'berry', 'cherry'];
console.log(fruits[fruits.indexOf('apple')]);
// expected output:
// apple
- A. The code causes an error because
fruits[fruits.indexOf('apple')]
isn't valid JavaScript syntax. - B. The code causes an error because
fruits.indexOf('apple')
doesn't return a valid index number. - C. The code causes an error because it outputs
0
instead of the expected output. - D. There is no error; the code generates the expected output.
Which statement best describes the error below?
const words = ['js', 'html', 'css'];
for (const w of words) {
console.log(words.toUpperCase());
}
// expected output:
// JS
// HTML
// CSS
- A. The code causes an error because
w
needs to be alet
variable. - B. The code causes an error because
words
is an array andtoUpperCase()
isn't a valid array function. - C. The code causes an error because it will output
['JS', 'HTML', 'CSS']
three times. - D. There is no error; the code generates the expected output.
Which statement best describes the error below?
const nums = [500, 200, 440];
const numStrings = [];
for (let i = 0; i <= nums.length; i++) {
numStrings.push(nums[i].toString());
}
console.log(numStrings);
// expected output:
// ['500', '200', '440']
- A. The code causes an error because
numStrings
needs to be alet
variable. - B. The code causes an error because
i <= nums.length
should bei < nums.length
- C. The code causes an error because
i++
isn't valid JavaScript syntax. - D. There is no error; the code generates the expected output.
Which statement best describes the error below?
function outputArgs(a, b, c) {
if (a) {
console.log(a);
}
if (b) {
console.log(b);
}
if (c) {
console.log(c);
}
}
outputArgs('hi', 'bye');
// expected output:
// hi
// bye
- A. The code causes an error because
outputArgs
takes in three arguments but it's being called with just two. - B. The code causes an error because it will output
hi
,bye
, andundefined
instead of the expected output. - C. The code causes an error because the
a
,b
, andc
variables haven't been initialized. - D. There is no error; the code generates the expected output.
What is the purpose of functions?
Functions can be used to create named blocks of code that can be executed/reused later. They help you keep code DRY and maintainable.
What is the difference between console.log
and return
?
A console.log() is an in-built javascript function that logs what is placed between the brackets to the terminal. Best use for console.log is for bug fixing, so it should be used prodigiously.
On the other hand, a return element can be used to return data from a function. It, however, can only be used once per function call.
You can use the two in conjuntion to log the returned data from a function.
What's the difference between defining and calling a function?
You define a function with the function keyword (or => for an arrow function), along with a name like myFunction, and then connecting that name to parentheses. You can then insert perameters into the parentheses that can be defined later with a function call.
You can call that function by using it's name, myFunction, and similarly connecting parentheses to your function call, which you can then optionally place arguments into.
Write a short description of the following data types:
String
Strings are a are a series of text contained within single quotes, double quotes, or backticks (also apparently called a grave accent.) They can even call variables into them if you use a template literal.
Number
A number is, well, a number. They can be integers, floats, and doubles. and integer is a whole number, a float is a number with a decimal, and a double is similar to a float, but can store for information. One might even say double the information.
Boolean
Boolean is a binary value of true or false. When referencing other data types a true value is found when there is presence, and false when there is absence (Number: 1 or -1 is true, 0 is false. String: 'this' is true, '' is false)
Array
Arrays are a data type that can be held in a variable which are capable of storing multiple data types within them. These items can be any combination of data types, incuding other arrays. An array is defined using square brackets [], and placing commas between each item (which I have been forgetting!)
Consider the following program:
let x = 5;
let y = 0;
while (y < 3) {
x = x + 5;
y = y + 1;
console.log(x);
}
The lines below represent the value of y
and x
at the end of each iteration of the while
loop.
Given the values for y
, replace the ??
with the values for x
. The first line has been
completed for you.
Initial values: y = 0, x = 5
1: y = 1, x = 10
2: y = 2, x = 15
3: y = 3, x = 20