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