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