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