← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

HTML and CSS lesson 25: JavaScript basics · Set 397 · 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 does alert() show? (a) a picture (b) a table (c) a new tab (d) a pop-up box
  2. 2.⚡ What number does this code print?
    let a = 38;
    let b = 26;
    console.log(a - b);
  3. 3.⚡ What does this code show?
    let name = "Kabir";
    console.log("Hi, " + name + "!");
    (a) Hi, Kabir! (b) name (c) Kabir (d) Hi, name!
  4. 4.⚡ Which JavaScript word repeats code? (a) for (b) let (c) alert() (d) if
  5. 5.⚡ Which JavaScript word writes in the console? (a) console.log() (b) let (c) for (d) if
  6. 6.⚡ What number does this code print?
    let a = 5;
    let b = 3;
    console.log(a * b);
  7. 7.⚡ What does this code show?
    let name = "Aman";
    alert("Hi, " + name + "!");
    (a) Hi, Aman! (b) Aman (c) Hi, name! (d) name
  8. 8.⚡ Which JavaScript word makes a new variable? (a) let (b) console.log() (c) for (d) if
  9. 9.⚡ What does this code show?
    let name = "Aman";
    alert("Welcome, " + name + "!");
    (a) Welcome, Aman! (b) name (c) Aman (d) Welcome, name!
  10. 10.⚡ Which word makes a new variable? (a) give (b) put (c) let (d) make
  11. 11.⚡ What does this code print? (Look at the quotes!)
    let x = "6";
    let y = 2;
    console.log(x + y);
    (a) 8 (b) Error (c) 62
  12. 12.⚡ Which JavaScript word shows a pop-up box? (a) console.log() (b) if (c) alert() (d) for
  13. 13.⚡ What number does this code print?
    let runs = 6;
    runs = runs + 11;
    runs = runs - 2;
    console.log(runs);
  14. 14.⚡ What number does this code print?
    let a = 7;
    let b = 2;
    console.log(a * b);
  15. 15.⚡ What does this code print? (Look at the quotes!)
    let x = "2";
    let y = 8;
    console.log(x + y);
    (a) 28 (b) 10 (c) Error
  16. 16.⚡ Which tag holds JavaScript in a page? (a) <js> (b) <style> (c) <code> (d) <script>
  17. 17.⚡ What number does this code print?
    let a = 59;
    let b = 27;
    console.log(a + b);
  18. 18.⚡ What number does this code print?
    let a = 58;
    let b = 9;
    console.log(a - b);
  19. 19.⚡ What does this code print? (Look at the quotes!)
    let x = "9";
    let y = 9;
    console.log(x + y);
    (a) Error (b) 99 (c) 18
  20. 20.⚡ What does this code print? (Look at the quotes!)
    let x = "2";
    let y = 7;
    console.log(x + y);
    (a) Error (b) 9 (c) 27
  21. 21.⚡ What number does this code print?
    let marks = 24;
    marks = marks + 17;
    marks = marks - 10;
    console.log(marks);
  22. 22.⚡ What does this code show?
    let name = "Arjun";
    console.log("Well done, " + name + "!");
    (a) Well done, name! (b) Well done, Arjun! (c) Arjun (d) name
  23. 23.⚡ What number does this code print?
    let books = 28;
    books = books + 3;
    books = books - 7;
    console.log(books);
  24. 24.⚡ What does this code print? (Look at the quotes!)
    let x = "8";
    let y = 2;
    console.log(x + y);
    (a) 10 (b) 82 (c) Error
  25. 25.⚡ What number does this code print?
    let a = 58;
    let b = 8;
    console.log(a + b);
  26. 26.⚡ What does this code print? (Look at the quotes!)
    let x = "2";
    let y = 5;
    console.log(x + y);
    (a) 25 (b) Error (c) 7
  27. 27.⚡ A JavaScript file usually ends with which extension? (a) .html (b) .css (c) .jpg (d) .js
  28. 28.⚡ Which JavaScript word runs code when true? (a) let (b) if (c) for (d) alert()
  29. 29.⚡ What does this code print? (Look at the quotes!)
    let x = "2";
    let y = 1;
    console.log(x + y);
    (a) Error (b) 3 (c) 21
  30. 30.⚡ What number does this code print?
    let a = 43;
    let b = 2;
    console.log(a + b);
  31. 31.⚡ What does this code show?
    let name = "Riya";
    console.log("Hello, " + name + "!");
    (a) Riya (b) Hello, name! (c) name (d) Hello, Riya!
  32. 32.⚡ What does this code show?
    let name = "Zoya";
    console.log("Hi, " + name + "!");
    (a) name (b) Hi, Zoya! (c) Hi, name! (d) Zoya
  33. 33.⚡ What number does this code print?
    let a = 5;
    let b = 6;
    console.log(a * b);
  34. 34.⚡ What does this code print? (Look at the quotes!)
    let x = "5";
    let y = 4;
    console.log(x + y);
    (a) Error (b) 9 (c) 54
  35. 35.⚡ What number does this code print?
    let score = 15;
    score = score + 17;
    score = score - 1;
    console.log(score);
  36. 36.⚡ What number does this code print?
    let coins = 20;
    coins = coins + 19;
    coins = coins - 3;
    console.log(coins);
  37. 37.⚡ What number does this code print?
    let runs = 10;
    runs = runs + 18;
    runs = runs - 4;
    console.log(runs);
  38. 38.⚡ What number does this code print?
    let books = 25;
    books = books + 13;
    books = books - 17;
    console.log(books);
  39. 39.⚡ What number does this code print?
    let a = 8;
    let b = 6;
    console.log(a * b);
  40. 40.⚡ What number does this code print?
    let a = 59;
    let b = 9;
    console.log(a - b);

Answer key

  1. a pop-up box
  2. 12
  3. Hi, Kabir!
  4. for
  5. console.log()
  6. 15
  7. Hi, Aman!
  8. let
  9. Welcome, Aman!
  10. let
  11. 62
  12. alert()
  13. 15
  14. 14
  15. 28
  16. <script>
  17. 86
  18. 49
  19. 99
  20. 27
  21. 31
  22. Well done, Arjun!
  23. 24
  24. 82
  25. 66
  26. 25
  27. .js
  28. if
  29. 21
  30. 45
  31. Hello, Riya!
  32. Hi, Zoya!
  33. 30
  34. 54
  35. 31
  36. 36
  37. 24
  38. 21
  39. 48
  40. 50

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