← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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