// Temperature /* { const far = (t) => ((t * 9/5) + 32) alert(far(0) + " F") } //RGB { const red = +prompt ("Write your value for red:") const green = +prompt ("Write your value for green :") const blue = +prompt ("Write your value for blue :") const f = (r, g, b) => { r = r.toString(16) if(r.length < 2) { r = r+r } g = g.toString(16) if(g.length < 2) { g = g + g } b = b.toString(16) if(b.length < 2) { b = b + b } let result = r+g+b alert (`Your color: #${result}`) } f(red, green, blue); } //FLATS { let floors = +prompt('Write amount of floors') let flatsInFloor = +prompt('Write amount of flats in floor') const answerForFlats = (floor,flats) => { let numberOfFlat = +prompt('Write number of flat') let remainderFlat = (numberOfFlat) % (floor * flats) let entrance = Math.ceil((numberOfFlat)/(floor * flats)) let numberOfFloor = Math.ceil(remainderFlat / flats); let result = {entrance, numberOfFloor} return(result) } console.log(answerForFlats(floors, flatsInFloor)) } //Credentials let functionForName = () => { const capitalize = str => { let result = str.split('')[0].toUpperCase() + str.slice(1,+Infinity).toLowerCase() return result //именно этот код обеспечит возврат результата функции } let firstname = capitalize(prompt("Write your name")) let surname = capitalize(prompt("Write your surname")) let fathername = capitalize(prompt("Write your thirdname")) let fullname = (firstname + " " + surname + " " + fathername) let result = {firstname, surname, fathername, fullname} return result } console.log(functionForName()) //New line { const functionForLine = l => l.split('\\n').join('\n') console.log(functionForLine( prompt("Write some text,you can use (\\n) for add new line"))) } //Prompt OR { const functionForAge = (age=0) => +prompt("How old are you?") console.log(2022 - functionForAge()) } //Login and password { const functionForLoginAndPassword = (login,password) => { let result = (login === "admin") && (password==="qwerty") ? true : false return result } console.log(functionForLoginAndPassword(prompt("login"), prompt("password"))) } //For Table { let arr = [[0,0,0,0,0], [0,1,2,3,4], [0,2,4,6,8], [0,3,6,9,12], [0,4,8,12,16]] const functionForArrInArr = arr => { let str = "" let i = 0 for (let number of arr){ str += "" + "" for (let letter of number){ str += (i % 2) ? "
" + letter + "" : "" + letter + "" } i++ } return document.write(str) } console.log(functionForArrInArr(arr)) } //Filter Lexics { const answer = prompt("Напиши шось").split(" ") const badWords = ["бляха", "пиздос", "лох", "шабля"] const funForFilter = (str, badStr) => { let strFilter = str.map(x=> badStr.includes(x) ? "" : x ).join(" ") return strFilter } console.log(funForFilter(answer, badWords)) } */ //Currency table { const functionForArrInArr = arr => { let str = "" let i = 0 for (let number of arr){ str += "" + "" for (let letter of number){ str += (i % 2) ? "
" + letter + "" : "" + letter + "" } i++ } return document.write(str) } const functionForJson = () => { fetch('https://open.er-api.com/v6/latest/USD').then(res => res.json()) .then(data => { const key = 0 const value = 1 const arr = Object.entries( data.rates ) let str = "" str += "" + "" for (let i = 0; i ${arr[i][key]} ` } str += "" for (let i = 0; i` rate1 = arr[i][value] for(let j=0; j ${crossRate.toFixed(2)} ` } } str += "" str += "
" + "
${arr[i][key]}
" console.log(data) //document.write(str) }) document.write(functionForArrInArr(functionForJson(arr))) } console.log(functionForArrInArr(functionForJson())) } //?????????????????????????????????????????????????????????????????????? /* // Form { const car = { "Name":"chevrolet chevelle malibu", "Cylinders":8, "Displacement":307, "Horsepower":130, "Weight_in_lbs":3504, "Origin":"USA", "in_production": false } const createObject = obj => { let str = "
" for ( const [key,value] of Object.entries(obj)){ if (typeof(value) === "string"){ str += ` ` } if(typeof(value) === "number"){ str += ` ` } if(typeof(value) === "boolean"){ str += ` ` } } str += "
" return document.write(str) } console.log(createObject(car)) } //Array of objects sort { var persons = [ {name: "Иван", age: 17}, {name: "Мария", age: 35}, {name: "Алексей", age: 73}, {name: "Яков", age: 12}, ] const funSort = (arr, name, booln=true) => { let result = arr.sort((first,second) => (first[name] < second[name]) == booln ? -1 : 1) return result } console.log(funSort(persons, "age")) console.log(funSort(persons, "age", false)) } //Table { const persons = [ { "Name":"chevrolet chevelle malibu", "Cylinders":8, "Displacement":307, "Horsepower":130, "Weight_in_lbs":3504, "Origin":"USA" }, { "Name":"buick skylark 320", "Miles_per_Gallon":15, "Cylinders":8, "Displacement":350, "Horsepower":165, "Weight_in_lbs":3693, "Acceleration":11.5, "Year":"1970-01-01", }, { "Miles_per_Gallon":18, "Cylinders":8, "Displacement":318, "Horsepower":150, "Weight_in_lbs":3436, "Year":"1970-01-01", "Origin":"USA" }, { "Name":"amc rebel sst", "Miles_per_Gallon":16, "Cylinders":8, "Displacement":304, "Horsepower":150, "Year":"1970-01-01", "Origin":"USA" }, ] let personsCopy = [] personsCopy = [...persons] const sortObj = (obj, line, booln = true) => { let result = obj.sort((a,b) => (a[line] < b[line]) == booln ? -1 : 1 ) return result } console.log(sortObj(personsCopy, "Displacement")) { let i = 0 let arrKeys = [] for (let key of persons){ arrKeys += Object.keys(persons[i]) + "," i++ } arrKeys = arrKeys.split(",").slice(0,-1) const arrFilter = (x) => { return x.filter((el1,el2) => x.indexOf(el1) === el2 ) } arrKeys = arrFilter(arrKeys) let arrValue =[] for (let arrVal of persons){ arrValue.push(arrKeys.map(y=>arrVal[y] === undefined? arrVal[y]="-" : arrVal[y])) } arrValue.unshift(arrKeys) let str = `` for( let firstString of arrValue){ str += `` for(let otherString of firstString){ str += `` } str += " " } str += "
${otherString}
" document.write(str) } let i = 0 let arrKeys = [] for (let key of personsCopy){ arrKeys += Object.keys(persons[i]) + "," i++ } arrKeys = arrKeys.split(",").slice(0,-1) const arrFilter = (x) => { return x.filter((el1,el2) => x.indexOf(el1) === el2 ) } arrKeys = arrFilter(arrKeys) let arrValue =[] for (let arrVal of personsCopy){ arrValue.push(arrKeys.map(y=>arrVal[y] === undefined? arrVal[y]="-" : arrVal[y])) } arrValue.unshift(arrKeys) let str = `` for( let firstString of arrValue){ str += `` for(let otherString of firstString){ str += `` } str += " " } str += "
${otherString}
" document.write(str) } //Divide in "divide.html" //Calc Func { const firstTask = (cost,amount,smokeDay) => { const oneCigar = cost / amount const month = smokeDay * 30 const moneyMonth = month * oneCigar let result = { first: oneCigar, second: month, third: moneyMonth } return result } firstTask(70, 20, +prompt("Write how cigarets you smoke evedy day:")) } */ //Calc Live //Используя пример из задания Divide и функцию из Calc Func сделайте несколько полей ввода в HTML, //меняя которые вы будете получать результат калькуляции в каком-то div.