← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

  1. 6
  2. 39
  3. in the console
  4. let
  5. 4
  6. 70
  7. actions and changes
  8. console.log()
  9. alert()
  10. 35
  11. 54
  12. 46
  13. if
  14. let
  15. Hello, Riya!
  16. 97
  17. 41
  18. 81
  19. 40
  20. 25
  21. 64
  22. 55
  23. 15
  24. Welcome, Riya!
  25. a pop-up box
  26. 57
  27. 110
  28. Hi, Meera!
  29. 24
  30. 36
  31. 29
  32. 21
  33. for
  34. Hi, Kabir!
  35. Well done, Aman!
  36. 22
  37. 53
  38. 27
  39. 58
  40. 9

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