You are on page 1of 2

Hand Note of Module: 20

1. Module Introduction, Math and round number.


Math.abs () The Math.abs() function returns the absolute value of a number. That
is, it returns x if x is positive or zero, and the negation of x if x is
negative.
Math.ceil () The Math.ceil() function always rounds a number up to the next
largest integer.
Math.floor() The Math.floor() function returns the largest integer less than or
equal to a given number.
Math.round() The Math.round() function returns the value of a number rounded to
the nearest integer.
Math.random() The Math.random() function returns a floating-point, pseudo-random
number in the range 0 to less than 1 (inclusive of 0, but not 1) with
Or approximately uniform distribution over that range — which you can
then scale to your desired range. The implementation selects the initial
Math.random()*6 seed to the random number generation algorithm; it cannot be chosen
or reset by the user.
2. Swap variable, swap without temp, destructing:
Destruction
var firstName = "Afif ";
var lastName = "Ahmed";
console.log(firstName, lastName); // Afif Ahmed
[firstName, lastName] = [lastName, firstName]
console.log(firstName, lastName); // Ahmed Afif
3. Find the max of two value, find the max of three value.
var number = [10, 50, 70, 35, 55, 60, 82, 40]
function maxFinder(yourInput) {
    var maxNumber = number[0];
    for (let element of yourInput) {
        if (element > maxNumber) {
            maxNumber = element;
        }
    }
    console.log(maxNumber);
}
maxFinder(number);
4. Some of number in an array
var number = [10, 50, 70, 35, 55, 60, 82, 40]
function addNumbers(inputNumber) {
    var grandTotal = 0;
    for (let numberItem of inputNumber) {
        grandTotal = grandTotal + numberItem;
    }
    console.log(grandTotal);
}

1|Page H a n d N o t e T a k e n b y : A fi f A h m e d
Hand Note of Module: 20
addNumbers(number);

5. Find the largest element of an array.


var number = [350, 420, 221, 450, 630, 780, 870, 520,];
function maxFinder(inputNumber) {
    var maxNumber = number[0];
    for (let element of inputNumber) {
        if (maxNumber < element) {
            maxNumber = element;
        }
    }
    console.log(maxNumber);
}
maxFinder(number);
6. Create a fibonacci series using for loop
7. Handle unexpected input using simple return.
function fabo(inputNumber) {
    var faboArray = [0, 1];
    if (typeof inputNumber != "number") {
        return "Please provide a valid number"
    }
    else if (inputNumber < 1) {
        return "Please provide a positive number which grater than 1"
    }
    else {
        for (let i = 2; i <= inputNumber; i++) {
            faboArray[i] = faboArray[i - 1] + faboArray[i - 2];
        }
        return faboArray;
    }
}
console.log(fabo(10));
console.log(fabo("hello"));
console.log(fabo(-10));

8. (advanced) Fibonacci element and series recursive way.

2|Page H a n d N o t e T a k e n b y : A fi f A h m e d

You might also like