What you will learn?
Creating simple JavaScript codes.
Creating and manipulating objects and arrays.
Writing unit tests using Jest
About this course
- Explain the importance of JavaScript in software development
- Demonstrate how to write JavaScript code inside the browser
- Demonstrate how to write basic JavaScript code: List common operators, conditional statements and loops
- Demonstrate how to use variables and output their values in the console
Prerequisites
Comments (0)
Introduction to JavaScript Programming Language
How JavaScript is used in the real world?
This online course is a self-paced learning experience. Because you are taking such an active role as a learner, it is important that you think about what your goals and expectations are:
This course is the second of a series that aims to help you learn more about web development.
In this course, you will explore the following:
Taking an online course can be overwhelming. How do you learn at your own pace and successfully achieve your goals?
Here are some general tips that can help you stay focused and on track.
You are well on your way to becoming a software developer.
You took the most important first step: you started.
While this specialization on Coursera will make you into a well-rounded junior developer, you are basically just getting started.
Here are some proven tips to make the transition to your new career as smooth as possible.
Learning how to program in JavaScript helps you prepare for a wide range of job opportunities. This is in part because it expands the possibilities of what you can build as a developer.
JavaScript is one of the most in-demand programming languages, as it is used in nearly all active websites. Its versatility enables developers to use popular libraries, plugins, and frameworks such as React, which improves efficiency and productivity.
With all flexibility that programming in JavaScript brings, it is no surprise that there are different careers that you might want to follow. However, no matter what career path you choose, you will always want to learn other technologies like HTML, CSS, React, Node.js, or Python, so you are more marketable.
Let’s cover a few of the most common roles you can get if you know how to program in JavaScript.
Let's get started. In this video, you will learn how to interpret the role of programming in the modern world. Recognize that programming is simply giving computers a set of instructions to complete using a programming language.
Why JavaScript
Programming in JavaScript
In this reading, you'll learn about comments in JavaScript. Additionally, you'll learn about the semi-colon in JavaScript: what it does and why it is used. You will then download a browser if you don't have one installed and run your first piece of JavaScript using the Console.
JavaScript Variables
In this exercise, you will practice declaring variables.
To check the output of your code, please enter it into the text box provided and click the "Run" button. This will execute the code and display the resulting output.
Tasks
Declare a new variable named petDog and give it the name Rex.
Declare a new variable named petCat and give it the name Pepper.
Console.log the petDog variable.
Console.log the petCat variable.
Console.log the text "My pet dog's name is: " and the petDog variable.
Console.log the text "My pet cat's name is: " and the petCat variable.
Declare another variable and name it catSound. Assign the string of "purr" to it.
Declare another variable and name it dogSound. Assign the string of "woof" to it.
Console.log the variable petDog, then the string "says", then the variable dogSound.
Console.log the variable petCat, then the string "says", then the variable catSound.
Reassign the value stored in catSound to the string "meow".
Console.log the variable petCat, then the string "now says", then the variable catSound.
Make sure to output all your variables. Feel free to play.
Here are the solutions to the previous exercise, which was to practice declaring variables.
Please note: The solutions presented here use single quotes and double quotes interchangeably to delimit pieces of text. This is done on purpose to illustrate that both ways of representing text are possible and acceptable so that you are aware of it.
JavaScript Data types
JavaScript Operators
JavaScript Numbers
JavaScript Strings
Booleans data type in JavaScript
In this reading, you will learn about additional operators, operator precedence and operator associativity. I'll also provide you with some examples of logical operators.
Task 1: Using the logical && operator
You are coding an RPG game, where each character has certain skill levels based on the value saved in their score.
Create a variable named score and set it to 8
Use console.log() that includes the string "Mid-level skills:" and compares the score variable to above 0 and below 10 using the && operator
The expected output in the console should be: "Mid-level skills: true".
Task 2: Using the logical || operator
Imagine you are coding a video game. Currently, you’re about to code some snippets related to the game over condition.
You need to code a new variable named timeRemaining and set it to 0. You also need to code a new variable named energy and set it to 10.
Next, you should write a piece of code that could be used to determine if the game is over, based on whether either the value of the timeRemaining variable is 0 or the value of the energy variable is 0.
Complete the task using the following steps:
Declare the variable timeRemaining, and assign the value of 0 to it.
Declare the variable energy, and assign the value of 10 to it.
Console log the following parameters: "Game over: ", and timeRemaining == 0 || energy == 0
Note that the expected output in the console should be: "Game over: true".
Try changing the timeRemaining variable to anything above 0 and then see how it affects the result.
Task 3: Using the modulus operator, %, to test if a given number is odd
You need to code a small program that takes a number and determines if it's an even number (like 2, 4, 6, 8, 10).
To achieve this task, you need to declare six variables, as follows:
The first variable, named num1, should be assigned a number value of 2.
The second variable, named num2, should be assigned a number value of 5.
The third variable, named test1, should be assigned the calculation of num1 % 2. Note: executing this code will return a number.
The fourth variable, named test2, should be assigned the calculation of num2 % 2. Note: executing this code will also return a number.
The fifth variable, named result1, should be assigned the result of comparing if the number stored in the test1 variable is not equal to 0, in other words, this: test1 == 0.
The sixth variable, named result2, should be assigned the result of comparing if the number stored in the test2 variable is not equal to 0, in other words, test2 == 0.
Run console log two times after you've set the variables:
The first console log should have the following code between parentheses: "Is", num1, "an even number?", result1
The second console log should have the following code between parentheses: "Is", num2, "an even number?", result2
Note: The output to the console should be as follows:
Is 2 an even number? true
Is 5 an even number? false
Try it yourself with different values to explore the modulus operator.
Task 4: Add numbers using the + operator
Console log the result of adding two numbers, 5 and 10, using the + operator.
Note: This task should be completed on a single line of code. The output in the console should be 15.
Task 5: Concatenate numbers and strings using the + operator
Code three variables:
The first variable should be a string with the following value: "Now in ". Name the variable now.
The second variable should be a number with the value: 3. Name the variable three.
The third variable should a string with the following value: "D!". Name the variable d.
Console log the following code: now + three + d.
Note: The expected output should be: "Now in 3D!".
Task 6: Use the += operator to accumulate values in a variable
Code a new variable and name it counter, assigning it to the value of 0.
On the next line, use the += operator to increase the value of counter by 5.
On the next line, use the += operator to increase the value of counter by 3.
On the fourth line, console log the value of the counter variable.
Note: The output value should be 8.
In this reading, you will learn about the history of JavaScript and the importance of ECMA (European Computer Manufacturers Association) and ECMAScript.
JavaScript is a programming language that had humble beginnings.