← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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