• 6. JAVASCRIPT – Loops
  • 7. JAVASCRIPT – Mantiqiy masalalar yechish 1
  • Leading Zeros
  • JAVASCRIPT – If, Switch, ternary




    Download 105.45 Kb.
    bet8/12
    Sana11.04.2023
    Hajmi105.45 Kb.
    #50258
    1   ...   4   5   6   7   8   9   10   11   12
    Bog'liq
    FRONT END full notes (7) (2022 05 08 17 42 47 UTC)
    00, mansur, 1, 2, 3-иловалар(1), Алишер, 1673 (1), MI-102 guruh Ergasheva M
    5. JAVASCRIPT – If, Switch, ternary
    • If, else if
    • Switch;
    switch(expression) {
    case x:
    // code block
    break;
    case y:
    // code block
    break;
    default:
    // code block
    }
    • Ternary;

    6. JAVASCRIPT – Loops
    • Foor loop
    While loop
    • do while loop
    var result = '';
    var i = 0;
    do {
    i += 1; result += i + ' ';
    }
    while (i > 0 && i < 5);
    // Despite i == 0 this will still loop as it starts off without the test
    console.log(result);


    7. JAVASCRIPT – Mantiqiy masalalar yechish


    1
    Create a function that takes in a number as a string n and returns the number without trailing and leading zeros.

    • Trailing Zeros are the zeros after a decimal point which don't affect the value (e.g. the last three zeros in 3.4000 and 3.04000).

    • Leading Zeros are the zeros before a whole number which don't affect the value (e.g. the first three zeros in 000234 and 000230).

    • removeLeadingTrailing("230.000") ➞ "230"


    • removeLeadingTrailing("00402") ➞ "402"


    • removeLeadingTrailing("03.1400") ➞ "3.14"


    • removeLeadingTrailing("30") ➞ "30"


    2.
    Create a function that takes in an array (slot machine outcome) and returns true if all elements in the array are identical, and false otherwise. The array will contain 4 elements.
    Examples
    testJackpot(["@", "@", "@", "@"]) ➞ true


    testJackpot(["abc", "abc", "abc", "abc"]) ➞ true


    testJackpot(["SS", "SS", "SS", "SS"]) ➞ true


    testJackpot(["&&", "&", "&&&", "&&&&"]) ➞ false


    testJackpot(["SS", "SS", "SS", "Ss"]) ➞ false


    3.
    Write a function that takes an integer i and returns an integer with the integer backwards followed by the original integer.
    To illustrate:
    123
    We reverse 123 to get 321 and then add 123 to the end, resulting in 321123.
    Examples
    reverseAndNot(123) ➞ 321123


    reverseAndNot(152) ➞ 251152


    reverseAndNot(123456789) ➞ 987654321123456789


    Download 105.45 Kb.
    1   ...   4   5   6   7   8   9   10   11   12




    Download 105.45 Kb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    JAVASCRIPT – If, Switch, ternary

    Download 105.45 Kb.