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