This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const uahEntered = prompt('please, enter UAH'); | |
const eurEntered = prompt('please, enter EUR'); | |
const uahToUsd = uahEntered/26.5; | |
const eurToUsd = eurEntered/1.15; | |
const totalUsd = uahToUsd + eurToUsd; | |
alert(`total amount in USD is ${totalUsd.toFixed(2) }`); | |
//next |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1) | |
function squareNum(n) { | |
return Math.pow(2, n) | |
} | |
console.log('square number is ' + squareNum(5)); //32 | |
// 2) | |
function getFactorial(n) { | |
let x = 1; | |
for(let i = 1; i <= n; i++) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Task 802 | |
const text = '2 lorem ipsum 1 dolor 64867789652 si amet 22'; | |
function findNums(str) { | |
let arr = str.split(' '); | |
const numsArr = arr.filter((item) => { | |
return item.search(/[0-9]/g) !== -1 ? item : null | |
}) | |
let maxLength = 0; | |
numsArr.map((item) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//make a sting '1+2+3+4' | |
let nums = ['1', '2', '3', '4']; | |
function join1(nums) { | |
return nums.join('+'); | |
} | |
console.log(join1(nums)); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// showing object info | |
let dog = { | |
name: 'Ronnie', | |
breed: 'chihuahua', | |
weight: 2.1, | |
color: 'white-red', | |
age: 5 | |
}; | |
for(let feature in dog) { | |
let info = feature + dog[feature]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//make an object where keys are symbols and values are numbers how many times those symbols are used in the string | |
let str = 'Ave Maria, gratia plena, Dominus tecum, benedicta tu in mulieribus et benedictus fructus ventris tui Jesus' | |
let arr = str.split(''); //transform the string into array splitting on every symbol | |
let counter = {}; //assign the empty object | |
for(let item of arr) { //iterate every symbol in the array | |
if(counter[item] === undefined) { //if there are no such key yet | |
counter[item] = 1 //then we assign this key with value 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let str = 'I learn JavaScript!'; | |
console.log(str.length); | |
console.log(str.substr(2, 5)); | |
console.log(str.substring(2, 7)); | |
console.log(str.slice(2, 7)); | |
console.log(str.indexOf('learn')); | |
const string = 'Чтобы избавиться от лишнего веса, нужно всего лишь не жрать'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//counters for 2 and 3 in array | |
let arr = [1, 2, 3, 2, 4, 3, 5, | |
6, 3, 2, 3]; | |
let counterThree = 0; | |
let counterTwo = 0; | |
for(let i of arr) { | |
if(i === 3) { | |
counterThree++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let arr = [2, 5, 9, 15, 0, 4]; | |
let result = []; | |
for(let i = 0; i < arr.length; i++) { | |
if(arr[i] > 3 && arr[i]< 10) { | |
result.push(arr[i]) | |
} | |
} | |
console.log(result); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//1 | |
function countCalls() { | |
let count = 0; | |
return function() { | |
return count += 1 | |
} | |
} | |
let counter = countCalls(); | |
console.log(counter()) | |
console.log(counter()) |
OlderNewer