123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401 |
- // 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 = "<table>"
- let i = 0
- for (let number of arr){
- str += "<tr>" + "<tr/>"
- for (let letter of number){
- str += (i % 2) ? "<td style=background-color:#FF0000>" + letter + "<td>" : "<td style=background-color:#000FFF>" + letter + "<td>"
- }
- 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 = "<table>"
- let i = 0
- for (let number of arr){
- str += "<tr>" + "<tr/>"
- for (let letter of number){
- str += (i % 2) ? "<td style=background-color:#FF0000>" + letter + "<td>" : "<td style=background-color:#000FFF>" + letter + "<td>"
- }
- 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 = "<table border=1px>"
- str += "<tr>" + "<td>" + "</td>"
- for (let i = 0; i<arr.length; i++){
- str += `<td> ${arr[i][key]} </td>`
- }
- str += "</tr>"
-
- for (let i = 0; i<arr.length; i++){
- str += `<tr><td> ${arr[i][key]} </td>`
- rate1 = arr[i][value]
- for(let j=0; j<arr.length; j++){
- rate2 = arr[j][value]
- crossRate = rate2 / rate1
- str += `<td> ${crossRate.toFixed(2)} </td>`
- }
- }
- str += "</tr>"
- str += "</table>"
-
-
- 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 = "<form>"
- for ( const [key,value] of Object.entries(obj)){
- if (typeof(value) === "string"){
- str += `<label>${key}: <input type="text" value="${value}" /> </label> `
- }
- if(typeof(value) === "number"){
- str += `<label>${key}: <input type="number" value="${value}" /> </label> `
- }
- if(typeof(value) === "boolean"){
- str += `<label>${key}: <input type="checkbox" value="${value}" /> </label> `
- }
-
- }
- str += "</form>"
- 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 = `<table border="1">`
- for( let firstString of arrValue){
- str += `<tr>`
- for(let otherString of firstString){
- str += `<td>${otherString}</td>`
- }
- str += " </tr>"
- }
- str += "</table>"
- 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 = `<table border="1">`
- for( let firstString of arrValue){
- str += `<tr>`
- for(let otherString of firstString){
- str += `<td>${otherString}</td>`
- }
- str += " </tr>"
- }
- str += "</table>"
- 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.
|