← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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