Kursinnehåll
Introduction to JavaScript
Introduction to JavaScript
1. Getting Started
First Javascript Console ApplicationChallenge: Showing some OutputChallenge: Outputing Multiple LinesDealing with NumbersChallenge: Working with NumbersChallenge: Calculating the Speed of a CarChallenge: Calculating Area of a TrapeziumOutputting Multiple ValuesChallenge: Consoling Meaningful OutputHow to Use Comments in Javascript?Challenge: Adding a CommentMulti-Line CommentsChallenge: Commenting out CodeWhat Is JavaScript anyway?
2. Manipulating Data
Storing DataChallenge: Declaring a VariableChallenge: Accessing Data From a VariableChallenge: Fixing Variable NamesChallenge: Reassigning a VariableConstantsChallenge: Declaring & Using ConstantsPerforming Arithmetic On VariablesChallenge: Making a Salary CalculatorChallenge: Adjusting Salary with a BonusExploring Primitive Data TypesChallenge: Declaring a Boolean ValueHow different Data Types InteractChallenge: Concatenating StringsChallenge: Creating User Profile & Activity Details
3. Conditional Statements
Comparison OperatorsChallenge: Checking Age EligibilityThe `if` StatementChallenge: Weather-Based Outfit RecommenderChallenge: Even or OddNested Conditional StatementsThe `else` ClauseChallenge: Improving Even or Odd CheckerChallenge: Temperature AdvisorThe `else if` ClauseChallenge: Grade Categorizer` AND` Logical OperatorChallenge: Checking if a Number is Even and PositiveOR Logical OperatorChallenge: Accessing Control System
4. Mastering Functions
What Are Functions?Challenge: Simple FunctionChallenge: Calculating the Speed of a CarScopesPassing Data into FunctionsChallenge: Fixing the Speed FunctionChallenge: Improving the Grade CategorizerTask: Defining a Compound FunctionReturning Data from FunctionsDefault ValuesChallenge: Email Auto-Responder with Default Parameters
5. Exploring Arrays
What Are Arrays?Challenge: Defining An ArrayChallenge: IndexingAdding Values to an ArrayChallenge: Pushing Elements to an ArrayRemoving Elements from an ArrayChallenge: Practicing `pop` & `shift`The `length` PropertyChallenge: Counting ElementsThe `includes` MethodChallenge: Searching for Animals in the Zoo
The `if` Statement
Definition
A conditional statement, also known as an if-statement, can be used to execute specific lines of code based on the result of a boolean expression.
The syntax of a conditional statement is:
js
Here boolean_expression
can be any expression which defines a condition. The code between the curly brackets ({}
) is executed if the boolean_expression
evaluates to true
.
Note
The code enclosed between the curly brackets ({}
) is collectively referred to as a Code Block.
For example:
let age = 18; if(age >= 18) { console.log("The user is old enough to drive."); }
We can have multiple if-statements in a program, giving us more control over which code block to execute. For example, we can further extend the previous code to output a different statement if the age is less than 18:
let age = 17; if(age >= 18) { console.log("The user is old enough to drive."); } if(age < 18) { console.log("The user is not old enough to drive"); }
1. What is a conditional statement used for in JavaScript?
2. What is the correct syntax for an if
statement?
3. What will be the output of the following code?
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 3. Kapitel 3