123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- //Confirms
- {
- let arr = [confirm("Are you man?"), confirm("Are you woman?"), confirm("Are you human?")]
- alert(arr)
- }
- //Prompts
- {
- let arr = [prompt("Are you man?"), prompt("Are you woman?"), prompt("Are you human?") ]
- alert(arr[1])
- }
- //Item access
- {
- let arr = ["cat", "dog", "elephant"]
- let userAnswer = +prompt("Choose number of element (0-2)")
- alert( arr[userAnswer] + ", length=" + arr.length)
- }
- //Item access
- {
- let arr=[1,2,3,4,5,6,7,8,9]
- let userAnswer = +prompt("Choose number of element (0-9)")
- console.log(arr[userAnswer])
- let userAnswer2 = +prompt("Write value for your choise")
- arr[userAnswer] = userAnswer2
- alert(arr[userAnswer] + ", all array: " + arr)
- }
- //Multiply 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]]
- }
- //Multiply table slice
- {
- 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]]
- arr[1] = arr[1].slice(-4)
- arr[2] = arr[2].slice(-4)
- arr[3] = arr[3].slice(-4)
- arr[4] = arr[4].slice(-4)
- let firstArr = arr.slice(-4)
- alert(firstArr)
- }
- //IndexOf Word
- {
- let userText = prompt("Write some text")
- let userWord = prompt("Write word for search")
- let result = userText.indexOf(userWord)
- if(result >=0){
- alert("Position of your word " + result)
- }
- else{
- alert('Error')
- }
- }
- //Reverse
- {
- const userArr = []
- userArr.push(prompt("Wtite your 1 element"))
- userArr.push(prompt("Wtite your 2 element"))
- userArr.push(prompt("Wtite your 3 element"))
- userArr.push(prompt("Wtite your 4 element"))
- userArr.push(prompt("Wtite your 5 element"))
- let newArr = []
- newArr.push(userArr.pop())
- newArr.push(userArr.pop())
- newArr.push(userArr.pop())
- newArr.push(userArr.pop())
- newArr.push(userArr.pop())
- alert(newArr)
- }
- //Reverse 2
- {
- let secondArr = []
- secondArr.unshift(newArr.shift())
- secondArr.unshift(newArr.shift())
- secondArr.unshift(newArr.shift())
- secondArr.unshift(newArr.shift())
- secondArr.unshift(newArr.shift())
- alert(secondArr)
- }
- //Copy
- {
- 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]]
- let copy = [...arr]
- }
- //Deep copy
- {
- 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]]
- let copy = arr.slice()
- arr.push(999)
- alert(copy)
- }
- //Array Equals
- {
- let x,y
- const arr = [x,y]
- const arr1 = arr
- const arr2 = arr
- arr1 === arr2
- }
- //Flat
- {
- 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 arrSpread = [...arr[0], ...arr[1],...arr[2],...arr[3],...arr[4]].length
- alert("Length " + arrSpread)
- }
- //Destruct
- {
- let userText = prompt("Write long text without space").split("")
- const [a,,,,b,,,,c,others] = userText
- alert(a + b + c)
- }
- //Destruct default
- {
- let userText = prompt("Write long text without space").split("")
- const [a=10,,,,b=20,,,,c=99,others] = userText
- alert(a + b + c)
- }
- //Multiply table rest
- {
- 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 [a, ...arr1] = arr
- const [b, ...arr2] = arr1[0]
- const [c, ...arr3] = arr1[1]
- const [d, ...arr4] = arr1[2]
- const [e, ...arr5] = arr1[3]
- const arrFinal = []
- arrFinal.push(arr2, arr3, arr4, arr5)
- alert(arrFinal)
- }
- //For Alert
- {
- const arr = ["John", "Paul", "George", "Ringo"]
- for (let name of arr){
- alert(`Hi,${name}`)
- }
- }
- //For Select Option
- {
- const currencies = ["USD", "EUR", "GBP", "UAH"]
- let str = "<select>"
- for (let currency of currencies){
- str += "<option>" + currency + "</option>"
- }
- str+= "</select>"
- document.write(str) //document.write отобразит ваш HTML на странице
- }
- //For Table Horizontal
- {
- const names = ["John", "Paul", "George", "Ringo"]
- let str = "<table>"
- for (let name of names){
- str += "<tr>" + name + "</tr"
- }
- str+= "</table>"
- document.write(str)
- }
- //For Table Vertical
- {
- const names = ["John", "Paul", "George", "Ringo"]
- let str = "<table>"
- for (let name of names){
- str += "<tr>"
- str += "<td>" + name + "</td>"
- str += "</tr>"
- }
- str+= "</table>"
- document.write(str)
- }
- //For Table Letters
- {
- const currencies = ["USD", "EUR", "GBP", "UAH"]
- let str = "<table>"
- for (let currency of currencies){ //цикл создает строки
- //одна итерация цикла создает ОДНУ СТРОКУ
- str += "<tr>"
- str += "</tr>"
- console.log(currency)
- for (let letter of currency){ //цикл создает ЯЧЕЙКИ в ОДНОЙ СТРОКЕ
- //одна итерация цикла создает ОДНУ ЯЧЕЙКУ
- str += "<td>" + letter + "</td>"
- console.log(letter)
- }
- }
- str+= "</table>"
- document.write(str)
- }
- //For Multiply 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]]
- 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++
- }
- document.write(str)
- }
- // Function Capitalize
- {
- const capitalize = str => {
- let result = str.split('')[0].toUpperCase() + str.slice(1,8).toLowerCase()
- return result //именно этот код обеспечит возврат результата функции
- }
- console.log(capitalize("cANBerRa")) //Canberra
- }
- //Map Capitalize
- {
- const answer = prompt("Write something").split(" ")
- const firstBig = answer.map(x => x[0].toUpperCase() + x.slice(1).toLowerCase())
- let result = firstBig.join(" ")
- alert(result)
- }
- //Filter Lexics
- {
- const answer = prompt("Напиши шось").split(" ")
- const badWords = ["бляха", "пиздос", "лох"]
- let result = answer.filter(x => badWords.includes(x)).join(" ")? false : true
- console.log(result)
- alert(result)
- }
- //Beep Lexics
- {
- let answer = prompt("Напиши шось").split(" ")
- let badWords = ["бляха", "пиздос", "лох"]
- let result = answer.map(x => badWords.includes(x)? ("BEEP") : x )
- console.log(result.join(" "))
- alert(result.join(" "))
- }
- //Reduce HTML
- {
- const currencies = ["USD", "EUR", "GBP", "UAH"]
- let str = "<select>"
- str += currencies.reduce( (a,b) => a + "<option>" + b + "</option>","")
- str += "</select>"
- document.write(str)
- }
|