JavaScript 1 - Variables, Strings, Numbers

Projected Time

About 2 hours

Prerequisites

Motivation

JavaScript is used on the frontend of almost every website. It’s also a widely-used scripting language that be used on the backend as well. Because of its ubiquity JavaScript is a must know language for any full-stack developer at all b2b or b2c companies. The JavaScript lessons set a solid foundation in JavaScript basics so we can use the language in more robust ways in later lessons.

Which companies use JavaScript variables and operators? Any company with an interactive website: Spotify, YouTube, meetup

Objectives

Participants will be able to:

Supplemental Materials

Lesson

JavaScript I - Variables, Strings, Numbers (video walkthrough of slides)

JavaScript I - Variables, Strings, Numbers (slides)

Things to Remember

Demonstration

Instructor demonstrates in the video walkthrough how to work with numbers and strings in JavaScript.

Independent Practice

Techtonica staff will assign pairs.

Activity: Basic Calculator

Concepts you’ve seen in this lesson that appear in this activity:

Concepts you’ve seen at Techtonica’s JS workshop that appear in this activity:

Using REPL.it, write a function called calculate that takes in 3 arguments. You can choose the parameter names for the arguments.

The calculate function should return the result of the math expression that you’ve specified using the arguments. You’ll need to code the logic so the function knows how to handle all the various math operators.

For example, the function call might look like this: calculate(3, '+', 7) And in this example, the function should return 10.

Feel free to use any resource you like if you get stuck, including Codecademy’s JavaScript course.

Group Practice

Swap pairs, read your new pair partner’s code, and do code reviews for each other. Did your second pair partner take a different approach than you did with your first pair partner? If so, how?

Swap pairs once more and repeat.

Challenge

Here are some other ways you can extend your calculator. Choose whichever one(s) sound most interesting to you!

  1. Add the ability to use a square root.
  2. Add the ability to use exponents.
  3. Add the ability to use constants, such as pi (3.14).
  4. Add the ability to operate on a third number.
  5. Incorporate a function from the Math library.

Check for Understanding

Form small groups and discuss: