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