Skip to content

Instantly share code, notes, and snippets.

@AbudiMutamba
Created June 28, 2021 10:04
Show Gist options
  • Save AbudiMutamba/122b4def334ba68f3a5563bf51f63790 to your computer and use it in GitHub Desktop.
Save AbudiMutamba/122b4def334ba68f3a5563bf51f63790 to your computer and use it in GitHub Desktop.
Ablestate cohort 1 JS online session 5
// Breakdown
// Create a function : function styles / expression/ decleration with the name mutiplyThreeNumbers
// Assign three indetifiers num1, num2, num3;
//Declare a variable multipliedNumbers and intialize
//Print to screen
/*
// PEMDAS
*parathesis
*Exponents(power)
*Multiplication
*Division
*Addition
*Substraction
*/
//function declaration
console.clear();
/**
* Decelaration sytnax/style
* @multiplyThreeNumbers
* @param {number} num1 - first number
* @param {number} num2 - second number
* @param {number} num3 -third number
* @returns {number} - a product
*/
function mutiplyThreeNumbers (num1, num2, num3){
// Do some validation
// Checked whether someone has provided the input or not
// Returning the right state
// Type checking
//if (!num1 || !num2 || !num3 ) return false;
//typeof multiplyThreeNumbers === 'number' ? true: false;
if(typeof multiplyThreeNumbers !== 'number' ){
return (num1 * num2 * num3);
}else{
return false;
}
}
let multipliedNumbers1 = mutiplyThreeNumbers( 2, 2, 2);
console.log(multipliedNumbers1);
//function expression
const MULTIPLY_THREE_NUMBERS = function (num1, num2, num3){
return (num1 * num2 * num3);
}
let multipliedNumbers2 = MULTIPLY_THREE_NUMBERS(3, 3, 3);
console.log(multipliedNumbers2);
//Arrow function
const MULTIPLY_NUMBERS = (num1, num2, num3) =>{
return (num1 * num2 * num3);
}
let multipliedNumbers3 = MULTIPLY_NUMBERS(4, 4, 4);
console.log(multipliedNumbers3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment