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
Do'stlaringiz bilan baham: |