Module-18 Practice Section

Video 18-0: Basic Concepts of variable all in one

Video 18-1: Module Introduction and Variable recap


            Two types of number : Integer: 120; float,/decimal 8.99;

            Variable naming convension: rules, best practice:

            1. single word
            2. no gap or speace
            3. no quote
            4. no keyword
            5. can not start with a number
            6. can not contain dash
            7. should use camelCase
        

Video 18-2 : Declare Array, array length and array index


            Three things to write array: first [], gap then ,=⇒ var friendAge = [11, 23, 67, 87]; or var nayikas= [ ‘mahi’ ‘shabnur’ , ‘opu’];

            console.log(array name.length)=⇒ number of array elements.==array position\ index starts from zero.
        

Video 18-3 : Array index, get and set by index, indexOf


var numbers = [45, 68, 78, 56, 89, 98]; //get element by index console.log(numbers[0])=> to finf first element=>45 var element = numbers[1]; console.log(element); Result-68; numbers[1] = 77; numbers[3] = 44; console.log(numbers); => [45, 77, 78,44, 89, 98];

Video 18-4 : Add or remove element from array using push, pop


            var friend =[’balam’, ‘kalam’, ‘salam’];

            friends.push(’galam’);

            console.log(friends);

            number.pop();=⇒ to remove last element from aray

            Search google: 

            How to add a element of the beginning of array.
        

Search Google: How to add an element to an array of the beginning. and how to remove first element of an array of javascript

Video 18-5 Compare variables and Comparison operator

Video 18-6 Make conditional decision, if-else, comparison


var iphonePrice = 79000; var myBudget = 9500; // if iphone price is less than my budget, i will buy the phone if(condition){ //will execute if the condition is true } if(chickenPrice < myMoney){ console.log('I will eat chicken'); } else{ console.log('I will eat potato'); }

Video 18-7 Handle multiple conditions, and or


            
                var isGraduated= true;
                var salary - 60000;
                if(isGraduated === true && salary > 50000){
                console.log('Eso biye kore feli')
                }
                else{
                console.log('tor kopale Biya nai')
                }

                if((isGraduated === true || salary > 50000) || cars>= 1){
                console.log('Eso prem kori');
                }
                else{
                console.log('Tumar kopale premnai')
                }
            
        

Video 18-8 (advanced) Multi stage condition and nested conditionsr

            
                var money = 10;
                var danishPrice = 45;
                var butterBread = 35;
                var toastBiscute = 20;
                if(danishPrice< money){
                console.log('Dan den danish khamu');
                }
                else if (butterBread < money){
                console.log('Butter bon khamu')
                }
                else if(toastBiscute < money){
                console.log('Toast biscute khamu)
                }
                else('Khali cha khamu')
            
        

18-9 Module summary and two more comparison

            - Array is a collection of similar data elements
            - Array index indicates the position of the element within the array
            - Array length is the total number of the elements in an array
            - The indexOf() method returns the index (position) of a specified value.
            - We van replace an element in an array with the help of array indices
            - e.g arrayName[index] = newValue
            - The push() method adds new items to the end of an array
            - The pop() method removes the last element from the end of an array
        

QUIZ

Q1: What is the starting index of an array?
Ans: 0

Q2: What would be the index of “developer” in the array? var dream = [“I”, “will”, “become”, “a”, “developer”, “inshallah”];
Ans: 4

Q3: How will you get the second element of the array arr = [3, 7, 10]?
Ans: arr[1]

Q4: What is the output of the following code snippet? let myArray = [1, 2, 3, 4, 5]; console.log(myArray[2]);
Ans: 3

Q5: Which of the following array methods adds an element to the end of an array?
Ans: push

Q6: What is the output of the following code snippet? let x = 5; let y = 10; if (x < y) { console.log("x is less than y"); } else { console.log("x is greater than or equal to y"); }
Ans: x is less than y

Q7S: What will be the output console.log(6 != 6);
Ans: false

Q8: What will be the output console.log(6 >= 6);
Ans: true

Q9: Where you don’t have to add a condition?
Ans: else

Q10: Which JavaScript array method removes and returns the last element of an array?
Ans: pop()

The End

Copyright© 2023 Allright Reserved