1 of 16

JavaScript Review

CSCI 344: Advanced Web Technologies

Spring 2025

2 of 16

Announcements

  1. Updated Schedule:
    • Quiz 2a will be next Friday (3/07)
    • Quiz 2b will be 2 Fridays after Spring Break(3/31)
  2. Added study guides and practice quizzes
  3. Tutorial 5 due tonight
  4. Quiz 1 graded and solutions posted
  5. Grading of HW2 and Tutorials 3-5 will be completed by Wednesday

3 of 16

Outline

  1. Practice Quiz (groups of 3-4)

4 of 16

Consider the following:�

let nums = [7, 4.5, 2, 1, 2.5];�let result = nums[0] + nums[2] + nums[4];

1. What is the VALUE of result?

2. What is the DATA TYPE of result?

5 of 16

Consider the following:

let result = 9 % 2;

1. What is the VALUE of the value stored in result?

2. What is the DATA TYPE of the value stored in result?

6 of 16

Consider the following:

let a = 4 ** 2;

let result = a / 2;�

1. What is the VALUE of result?

2. What is the DATA TYPE of the value stored in result?

7 of 16

Consider the following:�

const a = 10;

const b = 15;

const c = [4, 5, 6];

const result = (b - a) >= c.length;�

1. What is the VALUE of the value stored in result?

2. What is the DATA TYPE of the value stored in result?

8 of 16

Consider the following:

let myList = [[2, 3], [1, 8], [9, 6], [0, 7]];

let result = myList[2][0];

1. What is the VALUE of the value stored in result?

2. What is the DATA TYPE of the value stored in result?

9 of 16

Consider the following code block:�

let flowers = ['daisy', 'orchid', 'lily', 'tulip'];

let flower = flowers.pop()

flowers.push('rose')

flowers.push(flower);

console.log(flowers);�

What prints to the screen?

10 of 16

Consider the following:�

function f1(a, b) {

return a * b;

}

function f2(a, b) {

return b - a;

}

let x = f1(2, 3);

let y = f2(1, x);

let z = f2(y, f1(4, 5));

What is the value stored in x? (first group)

What is the value stored in y? (second group)

What is the value stored in z? (third group)

11 of 16

Using any kind of loop that you want, write a program that prints out all of the items in the “fruit” array to the JavaScript console:

let fruit = ['apple', 'orange', 'banana', 'grapefruit', 'lemon'];

let count = 0;

while (count < fruit.length) {

console.log(fruit[count];

count++;

}

For (let item of fruit) {

console.log(item);

}

12 of 16

Consider the following snippet of code....

const colors = [

'red', 'orange', 'yellow', 'green',

'blue', 'purple', 'indigo', 'violet'

];

const numbers = [1, 3, 5];

console.log(colors[5]);

console.log(numbers[1]);

console.log(colors[numbers[1]]);

13 of 16

Consider the following:�

const colors = [

'red', 'orange', 'yellow', 'green',

'blue', 'purple', 'indigo', 'violet'

]

for (let i = 0; i < colors.length; i += 2) {

console.log(i, colors[i]);

}

What will happen when this code is executed? If information prints to the screen, write what the output would be below.

14 of 16

Given the following code block, what prints to the console?�

let course = {

id: 250,

title: 'Intro to Music Composition',

department: 'Music',

semesters_offered: ['sp2021', 'sp2022', 'sp2023']

};

console.log(course.id, course.semesters_offered[2]);

15 of 16

Given the following code block, what prints to the console?

let a = true;

let b = true;

let c = false;

let result = null;

if (!a) {

result = 'horse';

} else if (a && c) {

result = 'donkey';

} else if (b || c) {

result = 'mule';

} else {

result = 'llama';

}

console.log(result);

16 of 16

What prints to the console after this code block executes?

let a = 0;

while (a < 16) {

a += 3;

if (a % 2 === 0) {

console.log(a, 'is even');

} else {

console.log(a, 'is odd);

}

}