← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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