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