JavaScript Worksheet: Basics
Code tip (Line by line): let x = 5; makes a variable x holding 5; x = x + 2; changes it to 7. console.log(…) writes in the console; alert(…) shows a pop-up box. Text in quotes + anything = joined text: "5" + 3 → "53".
NameDateTime takenScore ___ / 40
- 1.⚡ What does alert() show? (a) a table (b) a picture (c) a new tab (d) a pop-up box
-
2.⚡ What number does this code print?
let score = 13;
score = score + 10;
score = score - 17;
console.log(score); - 3.⚡ Which tag holds JavaScript in a page? (a) <script> (b) <js> (c) <code> (d) <style>
-
4.⚡ What number does this code print?
let runs = 6;
runs = runs + 11;
runs = runs - 9;
console.log(runs); -
5.⚡ What number does this code print?
let a = 35;
let b = 34;
console.log(a - b); -
6.⚡ What number does this code print?
let a = 39;
let b = 8;
console.log(a - b); - 7.⚡ A JavaScript file usually ends with which extension? (a) .css (b) .html (c) .jpg (d) .js
- 8.⚡ Where does console.log() show its output? (a) on the printer (b) in the address bar (c) on the title bar (d) in the console
-
9.⚡ What does this code print? (Look at the quotes!)
let x = "1";
let y = 9;
console.log(x + y); (a) 10 (b) 19 (c) Error -
10.⚡ What does this code print? (Look at the quotes!)
let x = "2";
let y = 4;
console.log(x + y); (a) Error (b) 24 (c) 6 -
11.⚡ What does this code show?
let name = "Riya";
alert("Hi, " + name + "!"); (a) name (b) Riya (c) Hi, Riya! (d) Hi, name! -
12.⚡ What number does this code print?
let runs = 10;
runs = runs + 19;
runs = runs - 23;
console.log(runs); -
13.⚡ What does this code show?
let name = "Arjun";
alert("Hello, " + name + "!"); (a) name (b) Hello, name! (c) Hello, Arjun! (d) Arjun -
14.⚡ What number does this code print?
let a = 56;
let b = 3;
console.log(a - b); -
15.⚡ What does this code print? (Look at the quotes!)
let x = "2";
let y = 3;
console.log(x + y); (a) 23 (b) Error (c) 5 -
16.⚡ What number does this code print?
let a = 28;
let b = 18;
console.log(a - b); -
17.⚡ What does this code show?
let name = "Riya";
alert("Welcome, " + name + "!"); (a) name (b) Welcome, name! (c) Welcome, Riya! (d) Riya -
18.⚡ What number does this code print?
let books = 18;
books = books + 12;
books = books - 24;
console.log(books); -
19.⚡ What number does this code print?
let books = 13;
books = books + 6;
books = books - 9;
console.log(books); -
20.⚡ What number does this code print?
let a = 8;
let b = 9;
console.log(a + b); -
21.⚡ What number does this code print?
let books = 22;
books = books + 20;
books = books - 30;
console.log(books); - 22.⚡ Which JavaScript word repeats code? (a) let (b) for (c) alert() (d) console.log()
-
23.⚡ What number does this code print?
let a = 44;
let b = 7;
console.log(a + b); - 24.⚡ Which JavaScript word runs code when true? (a) for (b) let (c) if (d) console.log()
-
25.⚡ What number does this code print?
let apples = 8;
apples = apples + 3;
apples = apples - 5;
console.log(apples); - 26.⚡ Which JavaScript word makes a new variable? (a) console.log() (b) if (c) for (d) let
- 27.⚡ Which word makes a new variable? (a) put (b) give (c) let (d) make
- 28.⚡ Which JavaScript word shows a pop-up box? (a) let (b) console.log() (c) for (d) alert()
-
29.⚡ What does this code print? (Look at the quotes!)
let x = "8";
let y = 7;
console.log(x + y); (a) 15 (b) 87 (c) Error -
30.⚡ What number does this code print?
let a = 45;
let b = 29;
console.log(a + b); -
31.⚡ What does this code print? (Look at the quotes!)
let x = "5";
let y = 4;
console.log(x + y); (a) 9 (b) Error (c) 54 -
32.⚡ What number does this code print?
let a = 6;
let b = 2;
console.log(a * b); -
33.⚡ What number does this code print?
let apples = 7;
apples = apples + 3;
apples = apples - 9;
console.log(apples); -
34.⚡ What number does this code print?
let coins = 26;
coins = coins + 13;
coins = coins - 33;
console.log(coins); -
35.⚡ What does this code print? (Look at the quotes!)
let x = "6";
let y = 3;
console.log(x + y); (a) 9 (b) Error (c) 63 -
36.⚡ What number does this code print?
let a = 8;
let b = 3;
console.log(a * b); -
37.⚡ What number does this code print?
let a = 9;
let b = 2;
console.log(a * b); -
38.⚡ What number does this code print?
let marks = 18;
marks = marks + 5;
marks = marks - 13;
console.log(marks); -
39.⚡ What does this code print? (Look at the quotes!)
let x = "6";
let y = 1;
console.log(x + y); (a) 7 (b) 61 (c) Error -
40.⚡ What number does this code print?
let score = 25;
score = score + 6;
score = score - 20;
console.log(score);
Answer key
- a pop-up box
- 6
- <script>
- 8
- 1
- 31
- .js
- in the console
- 19
- 24
- Hi, Riya!
- 6
- Hello, Arjun!
- 53
- 23
- 10
- Welcome, Riya!
- 6
- 10
- 17
- 12
- for
- 51
- if
- 6
- let
- let
- alert()
- 87
- 74
- 54
- 12
- 1
- 6
- 63
- 24
- 18
- 10
- 61
- 11
Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids