Last active
November 30, 2021 18:01
-
-
Save vladislavaSim/44378569215b6fce25b5384c1022e275 to your computer and use it in GitHub Desktop.
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); | |
// | |
let nums = [2, 0, 78, -21, 4, 88, -1, -81, 22]; | |
let sum = 0; | |
for(let i of nums) { | |
if(i > 0) { | |
sum += i | |
} | |
} | |
console.log(sum); | |
// | |
let arr = [1, 2, 5, 9, 4, 13, 4, 10]; | |
for(let i of arr) { | |
if(i === 4) { | |
console.log('4 is here') | |
break; | |
} | |
} | |
// | |
let arr = [225, 12, 71, 32, 50, 9, 5, 41, 1, 13, 20]; | |
for(let i of arr) { | |
i = String(i) | |
if(i.startsWith('1') || i.startsWith('2') || i.startsWith('5')) { | |
console.log(+i) | |
} | |
} | |
// | |
let nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]; | |
let str = '-'; | |
for(let i = 1; i < nums.length + 1; i++) { | |
str += i + '-' | |
} | |
console.log(str) | |
// | |
let week = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']; | |
let day; | |
for(let i = 0; i < week.length; i++) { | |
day = week[i] | |
if (day === 'sat' || day === 'sun') { | |
day = day.bold() | |
} | |
const p = document.createElement('p'); | |
p.innerHTML = day; | |
document.body.appendChild(p) | |
} | |
// | |
let week = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun']; | |
let day = prompt('enter a day of week shortly'); | |
for(let i = 0; i < week.length; i++) { | |
if (week[i] === day) { | |
week[i] = week[i].italics() | |
} | |
const p = document.createElement('p'); | |
p.innerHTML = week[i]; | |
document.body.appendChild(p) | |
} | |
// | |
let num = 1000; | |
let n = 0; | |
do{ | |
num /= 2 | |
n++ | |
} while (num > 50); | |
console.log(n) | |
console.log(num) | |
// | |
function squareNum(n) { | |
return Math.pow(n, 2) | |
} | |
console.log(squareNum(6)) | |
// | |
function sum(x, y) { | |
return x+y | |
} | |
console.log(sum(5, 10)) | |
// | |
function calc(x, y, z) { | |
return (x-y)/z | |
} | |
console.log(calc(50, 10, 2)) | |
// | |
let n = prompt('enter a number of the day') | |
function showDay() { | |
const week = ['понедельник', 'вторник', 'среда', 'четверг', 'пятница', 'суббота', 'воскресенье'] | |
for(let i = 0; i < week.length; i++) { | |
if(+n === i+1) { | |
return week[i] | |
} | |
} | |
} | |
console.log(showDay()) | |
// | |
let sum = 0; | |
let array = [2.777, -0.335794, -1.524, 9.25, 76, 721.665, -83.2]; | |
for(let item of array) { | |
if(item < 0) { | |
sum += item | |
} | |
} | |
console.log(sum); | |
// | |
let num = prompt('enter a number'); | |
num = +num; | |
let multiply = 1; | |
let arr = []; | |
for(let i = 0; i < num; i++) { | |
arr.push(Math.random() * (999999 - -999999) + -999999); | |
if(Math.abs(arr[i]) > 7) { | |
multiply *= arr[i] | |
} | |
} | |
console.log(multiply); | |
// | |
let num = prompt('enter a number'); | |
num = +num; | |
let sum = 0; | |
let arr = []; | |
for(let i = 0; i < num; i++) { | |
arr.push(Math.floor(Math.random() * 1000)); | |
if(arr[i] % 3 === 0) { | |
sum += arr[i] | |
} | |
} | |
console.log(sum); | |
// | |
let num = prompt('enter a number'); | |
num = +num; | |
let arr = []; | |
let maxNum = 0; | |
let biggestNumIndex = 0; | |
for(let i = 0; i < num; i++) { | |
arr.push(Math.floor(Math.random() * 1000)); | |
if(arr[i] > maxNum) { | |
maxNum = arr[i] | |
} | |
} | |
biggestNumIndex = arr.indexOf(maxNum) | |
console.log(biggestNumIndex); | |
// | |
let luckyNumbers = []; | |
function sum(x, y) { | |
return Number(x) + Number(y) | |
} | |
function getLuckyNumbers() { | |
for (let i = 1001; i < 10000; i++) { | |
i = String(i) | |
let num1 = i[0]; | |
let num2 = i[1]; | |
let num3 = i[2]; | |
let num4 = i[3]; | |
if (sum(num1, num2) === sum(num3, num4)) { | |
luckyNumbers.push(+i); | |
} | |
} | |
return luckyNumbers | |
} | |
console.log(getLuckyNumbers()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment