Posts

Showing posts from November, 2020

JavaScript for Beginners - Functions (P: IX)

Image
Functions A JavaScript function is a block of code designed to perform a particular task.   The main advantages of using a function; -           Re-Use - define the code once and can re-use many times. -           Use the same code many times with different arguments, to produce different results Note: A JavaScript function is executed when “something” invokes or call it. Defining a function To define a function, use the “ function ” keyword, followed by a name , followed by a set of parentheses (). Calling a function To execute the function, you need to call it. To call a function, start with the name of the function, then follow it with the arguments in parenthesis.   Note: Always remember to end the statement with a semicolon after calling the function. Once the function is defined JavaScript allows you to call it as many times as you want to.

JavaScript for Beginners - Basic Concepts Conditionals and Loops (P: VIII)

Image
  The If Statement Very often when you write code, you want to perform different actions based on different conditions. You can do this by using conditional statements in your code. Use if to specify a block of code that will be executed if a specified condition is true The statements will be executed only if the specified condition is true . Example: Result: If the condition evaluates to false, the alert statement is skipped and the program continues with the line after the if statement’s closing curly brace. Note: Note the if is in lowercase letters. Uppercase letters (If or IF) will generates an error The if else Statement Use the else statement to specify a block of code that will execute if the condition is false The example below demonstrates the use if an if... ese statement The above example says: -           If num1 is greater than num2, alert “This is my first condition” -       ...

JavaScript for Beginners - Basic Operators (P: VII)

Image
  Math Operators Arithmetic operators perform arithmetic functions on numbers (literals or variables) Operator Description Example + Addition 50 + 5 = 55 -             Subtraction 20 -10 = 10 * Multiplication 40 * 2 = 80 / Division 20 / 4 = 5 % Modules 56 % 3 = 2 ++ Increment var x = 10; x++, Now x = 11 -- Decrement var x = 10; x--, Now x = 9   Addition In the example below, the addition operator is used to determine the sum of two numbers You can add as many numbers or variables together as you want or need to Multiplication The multiplication operator (*) multiplies one number by the other. Division The / operator is used to perform division operations: The Modules Modu...