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