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 this code print? (Look at the quotes!)
let x = "2";
let y = 1;
console.log(x + y); (a) Error (b) 21 (c) 3 - 2.⚡ Which JavaScript word writes in the console? (a) let (b) if (c) alert() (d) console.log()
- 3.⚡ Which word makes a new variable? (a) put (b) let (c) make (d) give
- 4.⚡ Which JavaScript word shows a pop-up box? (a) alert() (b) if (c) let (d) console.log()
-
5.⚡ What does this code print? (Look at the quotes!)
let x = "9";
let y = 2;
console.log(x + y); (a) Error (b) 11 (c) 92 - 6.⚡ Which JavaScript word makes a new variable? (a) if (b) let (c) for (d) alert()
-
7.⚡ What number does this code print?
let a = 42;
let b = 1;
console.log(a + b); -
8.⚡ What number does this code print?
let a = 29;
let b = 23;
console.log(a - b); - 9.⚡ Which JavaScript word repeats code? (a) for (b) let (c) alert() (d) console.log()
-
10.⚡ What number does this code print?
let books = 28;
books = books + 20;
books = books - 47;
console.log(books); - 11.⚡ A JavaScript file usually ends with which extension? (a) .jpg (b) .css (c) .html (d) .js
-
12.⚡ What number does this code print?
let coins = 20;
coins = coins + 3;
coins = coins - 1;
console.log(coins); -
13.⚡ What does this code print? (Look at the quotes!)
let x = "1";
let y = 1;
console.log(x + y); (a) 11 (b) 2 (c) Error -
14.⚡ What number does this code print?
let coins = 12;
coins = coins + 19;
coins = coins - 26;
console.log(coins); - 15.⚡ Which tag holds JavaScript in a page? (a) <script> (b) <code> (c) <js> (d) <style>
-
16.⚡ What number does this code print?
let a = 41;
let b = 26;
console.log(a + b); -
17.⚡ What number does this code print?
let a = 25;
let b = 8;
console.log(a + b); -
18.⚡ What does this code print? (Look at the quotes!)
let x = "4";
let y = 6;
console.log(x + y); (a) 46 (b) 10 (c) Error -
19.⚡ What does this code print? (Look at the quotes!)
let x = "8";
let y = 5;
console.log(x + y); (a) 85 (b) Error (c) 13 -
20.⚡ What number does this code print?
let a = 5;
let b = 3;
console.log(a * b); -
21.⚡ What number does this code print?
let a = 55;
let b = 39;
console.log(a - b); -
22.⚡ What number does this code print?
let runs = 21;
runs = runs + 12;
runs = runs - 25;
console.log(runs); -
23.⚡ What does this code show?
let name = "Meera";
alert("Well done, " + name + "!"); (a) name (b) Well done, name! (c) Well done, Meera! (d) Meera -
24.⚡ What does this code show?
let name = "Arjun";
alert("Welcome, " + name + "!"); (a) Arjun (b) Welcome, name! (c) Welcome, Arjun! (d) name -
25.⚡ What number does this code print?
let a = 7;
let b = 4;
console.log(a * b); -
26.⚡ What does this code show?
let name = "Aman";
alert("Hello, " + name + "!"); (a) Aman (b) Hello, Aman! (c) Hello, name! (d) name - 27.⚡ What does alert() show? (a) a new tab (b) a pop-up box (c) a table (d) a picture
-
28.⚡ What does this code print? (Look at the quotes!)
let x = "2";
let y = 8;
console.log(x + y); (a) Error (b) 28 (c) 10 -
29.⚡ What does this code print? (Look at the quotes!)
let x = "7";
let y = 2;
console.log(x + y); (a) 9 (b) Error (c) 72 -
30.⚡ What does this code print? (Look at the quotes!)
let x = "8";
let y = 1;
console.log(x + y); (a) 81 (b) Error (c) 9 -
31.⚡ What number does this code print?
let a = 35;
let b = 33;
console.log(a + b); -
32.⚡ What does this code show?
let name = "Meera";
console.log("Hello, " + name + "!"); (a) Meera (b) name (c) Hello, Meera! (d) Hello, name! - 33.⚡ Where does console.log() show its output? (a) in the address bar (b) in the console (c) on the printer (d) on the title bar
-
34.⚡ What number does this code print?
let score = 29;
score = score + 9;
score = score - 37;
console.log(score); -
35.⚡ What does this code show?
let name = "Zoya";
console.log("Hello, " + name + "!"); (a) name (b) Hello, Zoya! (c) Hello, name! (d) Zoya -
36.⚡ What number does this code print?
let books = 28;
books = books + 6;
books = books - 21;
console.log(books); -
37.⚡ What does this code show?
let name = "Kabir";
alert("Welcome, " + name + "!"); (a) Kabir (b) name (c) Welcome, Kabir! (d) Welcome, name! -
38.⚡ What number does this code print?
let marks = 9;
marks = marks + 3;
marks = marks - 5;
console.log(marks); -
39.⚡ What number does this code print?
let books = 8;
books = books + 8;
books = books - 8;
console.log(books); -
40.⚡ What number does this code print?
let books = 10;
books = books + 2;
books = books - 9;
console.log(books);
Answer key
- 21
- console.log()
- let
- alert()
- 92
- let
- 43
- 6
- for
- 1
- .js
- 22
- 11
- 5
- <script>
- 67
- 33
- 46
- 85
- 15
- 16
- 8
- Well done, Meera!
- Welcome, Arjun!
- 28
- Hello, Aman!
- a pop-up box
- 28
- 72
- 81
- 68
- Hello, Meera!
- in the console
- 1
- Hello, Zoya!
- 13
- Welcome, Kabir!
- 7
- 8
- 3
Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids