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