← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 25
  2. if
  3. let
  4. 19
  5. 42
  6. 35
  7. alert()
  8. 53
  9. 25
  10. 7
  11. a pop-up box
  12. Hi, Meera!
  13. console.log()
  14. 18
  15. 82
  16. 59
  17. 55
  18. 14
  19. 20
  20. 57
  21. actions and changes
  22. 64
  23. Well done, Aman!
  24. 72
  25. 1
  26. 66
  27. 37
  28. for
  29. Hello, Meera!
  30. 78
  31. 35
  32. 44
  33. 61
  34. <script>
  35. Hello, Aman!
  36. 12
  37. 5
  38. 7
  39. 17
  40. 21

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