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