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