← JavaScript basics lesson New set →

JavaScript Worksheet: Basics

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

Answer key

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

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