Unit V - Lesson 4 | Codetantra HTML

Unit V - Lesson 4 | Codetantra HTML

Unit V - Lesson 4

### 6.4.1. if-else statement

    // write your code below this line
    if((year % 4 === 0 && year % 100 !==0) || year % 400 === 0){
        var nDays = 366;
    }else{
        var nDays = 365;
    }

6.4.2. switch-case statement

    // write your code below this line

    switch (colorCode) {
        case 'V':
            colorName='Violet';
            break;
        case 'I':
            colorName='Indigo';
            break;
        case 'B':
            colorName='Blue';
            break;
        case 'G':
            colorName='Green';
            break;
        case 'Y':
            colorName='Yellow';
            break;
        case 'O':
            colorName='Orange';
            break;
        case 'R':
            colorName='Red'
            break;
    }

6.5.1. for loop

    function computeSeries(){
        let seriesN = 0;
        for(let i = 1; i<=N; i++){
            seriesN += i ** 2;
        }
        window.seriesN = seriesN;
    }
    computeSeries();

6.5.2. for loop - continue statement

    let sum = 0;
    for(let i = 1; i<=N; i++){
        let square = i * i;
        if(square % 10 === 0){
            continue;
        }
        sum+=square;
    }
    seriesN = sum;

6.5.3. while loop

    let a = 1, b = 1;
    if (N === 1 || N === 2){
        fibN = 1;
    }else{
        let count = 2;
        while(count < N){
            fibN = a + b;
            a = b;
            b = fibN;
            count ++
        }
    }
    fibN;