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