← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

HTML and CSS lesson 25: JavaScript basics · Set 655 · 40 questions
TalentJR

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

Answer key

  1. .js
  2. <script>
  3. 0
  4. let
  5. 17
  6. 75
  7. actions and changes
  8. in the console
  9. for
  10. Hi, Arjun!
  11. 50
  12. alert()
  13. Welcome, Arjun!
  14. 14
  15. Well done, Arjun!
  16. a pop-up box
  17. if
  18. Hi, Meera!
  19. 38
  20. 1
  21. console.log()
  22. 23
  23. 21
  24. Welcome, Riya!
  25. 20
  26. 96
  27. 27
  28. 7
  29. 15
  30. Hi, Zoya!
  31. Hi, Aman!
  32. 69
  33. 10
  34. 69
  35. 8
  36. 14
  37. 12
  38. 64
  39. 43
  40. 32

Free html and css lessons, practice and worksheets at talentjr.in/html-css-for-kids