Course Content
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
Using Loops with Arrays
Loops enable us to efficiently go through all or specific elements of an array.
For example, we can use a for loop to iterate through all elements of an array and output them:
let numbers = [1, 1, 2, 3, 5, 8, 13, 21]; for(let i = 0; i < numbers.length; i++) { console.log("Element " + (i + 1) + " of the array is: " + numbers[i]); }
This is especially useful when we need to perform an operation on multiple elements in an array:
let numbers = [1, 1, 2, 3, 5, 8, 13, 21]; console.log("Before:", numbers); for(let i = 0; i < numbers.length; i++) { numbers[i] *= 2; } console.log("After:", numbers);
We can use a while
or a do-while
loop for this purpose as well, however, that is not the convention.
let numbers = [1, 1, 2, 3, 5, 8, 13, 21]; console.log("Before:", numbers); let i = 0; while(i < numbers.length) { numbers[i] *= 2; i += 1; } console.log("After:", numbers);
Even though the same results can be achieved using while
or do-while
loops, it is recommended to use a for
loop when iterating through arrays because it is the conventional and more readable approach.
1. What does the following code output?
2. Does the following code modify the original array?
Everything was clear?
Thanks for your feedback!
SectionΒ 6. ChapterΒ 7