123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406 |
- //////html tree
- function htmlTree() {
- var body = {
- tagName: "body",
- subTags: [
- {
- tagName: "div",
- subTags: [
- {
- tagName: "span",
- text: "Enter a data please:",
- },
- {
- tagName: "br/",
- },
- {
- tagName: "input",
- attrs: {
- type: "text",
- id: "name"
- },
- },
- {
- tagName: "input",
- attrs: {
- type: "text",
- id: "surname"
- }
- }
- ]
- },
- {
- tagName: "div",
- subTags: [
- {
- tagName: "button",
- text: "OK",
- attrs: {
- id: "ok",
- }
- },
- {
- tagName: "button",
- text: "Cancel",
- attrs: {
- id: "cancel"
- }
- }
- ]
- }
- ],
- }
- alert(body.subTags[1].subTags[1].text)
- alert(body.subTags[0].subTags[3].attrs.id)
- }
- // htmlTree()
- //////
- //////
- /////declarative fields
- /////object links
- function declarativeFriends() {
- var notebook = {
- brand: prompt("Name of brand of notebook"),
- type: prompt("Number of type in style 'XXX XX'"),
- model: prompt("Model code"),
- ram: +prompt("Ram"),
- size: prompt("Size"),
- weight: +prompt("Weight in style X.X"),
- resolution: {
- width: +prompt("Width"),
- height: +prompt("Height"),
- },
- };
-
- var phone = {
- brand: prompt("Name of brand of phone"),
- model: prompt("Model code"),
- ram: +prompt("Ram"),
- color: prompt("What's color?"),
- };
-
- var person = {
- name: prompt("Write your name?"),
- surname: prompt("Write your surname?"),
- married: confirm("Are you married? Click 'ok' if answer is 'yes' and 'cancel' if 'no'"),
- }
- person.laptop = notebook;
- person.smartphone = phone;
- phone.owner = person;
- notebook.owner = person;
- alert("Notebook \n owner: " + notebook.owner.name + "\n brand: " + notebook.brand + "\n type: " + notebook.type + "\n model: " + notebook.model + "\n ram: " + notebook.ram + "\n size: " + notebook.size + "\n weight: " + notebook.weight + "\n width: " + notebook.resolution.width + "\n height: " + notebook.resolution.height)
- alert("Phone\n owner: " + phone.owner.name + "\n brand: " + phone.brand + "\n model: " + phone.model + "\n ram: " + phone.ram + "\n color: " + phone.color)
- alert("Person\n name " + person.name + "\n surname: " + person.surname + "\n married: " + person.married + "\n laptop: " + notebook.brand + "\n smartphone: " + phone.brand)
- if (person.smartphone.owner.laptop.owner.smartphone == person.smartphone){
- alert ("You're superman")
- } else {
- alert ("Try again, loser")
- }
- }
- // declarativeFriends()
- //////////////
- /////imperative array fill 3
- function imperativeArray() {
- let imperative = [];
- imperative[0] = prompt("How old are you?"), imperative[1] = prompt("How old is your father?"), imperative[2] = prompt("How old is your mother?")
- alert("So you are " + imperative[0] + " years old. Your father is " + imperative[1] + " and mother is " + imperative[2])
- }
- // imperativeArray()
- ////////
- //////
- ///while confirm
- function whileConfirm(question) {
- question = false;
- while(question === false) {
- question = confirm("Are you're dead?")
- }
- }
- // whileConfirm()
- //////////
- ////array fill
- function arrayFill() {
- var array = [];
- var once = true;
- while(!!once === true || once === "") {
- once = prompt("Write something")
- array.push(once)
- }
- alert("The array's length is " + array.length)
- }
- // arrayFill()
- ///////
- /////array fill nopush
- function arrayFillNopush() {
- var i = 0;
- var array = [];
- var once = prompt("Write something");
- while(!!once === true || once === "") {
- array[i++] = once;
- once = prompt("Write something");
- }
- alert("The array's length is " + array.length)
- }
- // arrayFillNopush()
- ////infinite probability
- function infiniteProbably() {
- let haha = true;
- let i = 0;
- let array = []
- debugger
- while (haha === true) {
- i = Math.random();
- array.push(i)
- if (i > 0.9) {
- break;
- }
- confirm("And again")
- }
- alert ("You had " + array.length + " expected output")
- }
- // infiniteProbably()
- //////
- ///////empty loop
- function emptyLoop() {
- var again = null;
- while((again = prompt("And again?")) === null) {
- }
- }
- // emptyLoop()
- ///////////
- //////progression sum
- function progressionSum() {
- let b = (+prompt("Chose your number"))
- let sum = 1;
- let a = 1;
- for (let i = 1; b > a; i++){
- a = a + 3;
- if (a > b) {
- alert(sum + " but it can have an error in 1-2 count")
- return
- } else {
- sum = sum + a;
- }
- }
- alert (sum)
- }
- // progressionSum()
- //////////////////
- ////chess one line - Написала два варианта
- function chessOneLine() {
- let string = "";
- for(let num = +prompt("String length is...");0 < num; num--){
- string += "#" + " ";
- }
- return console.log(string)
- }
- // chessOneLine()
- ///////////////
- function chessOneLine2() {
- let num = +prompt("String length is...");
- let string = "";
- for(;num > 0; num = num - 1){
- if (num % 2 == 0) {
- string += "#";
- } else {
- string += " ";
- }
- }
- return console.log(string)
- }
- // chessOneLine2()
- ///////
- /////numbers
- function numberCucle() {
- let stringMass = "";
- for(let i = 0; i < 10; i++) {
- let string = "";
- for (let j = 0; j < 10; j++) {
- string += j
- }
- stringMass += string + "\n"
- }
- console.log(stringMass)
- }
- // numberCucle()
- ///////////////////
- //////////
- ////chess
- function chess(){
- let desk = "";
- let string = "";
- let x = +prompt("Please write a size of horizontal")
- let y = +prompt("Please write a size of vertical")
- for(let i = 0; i < y; y--){
- for(let j = x; j > 0; j--) {
- if(y % 2 === 0){
- if(j % 2 === 0) {
- string += "#";
- } else {
- string += ".";
- }
- } else {
- if(j % 2 === 0) {
- string += ".";
- } else {
- string += "#";
- }
- }
- }
- desk += string + "\n"
- string = "";
- }
- console.log(desk)
- }
- chess()
- ////////////
- /////////
- //cubes
- function cubes() {
- var array = [];
- var arrayString = "";
- array.length = +prompt("And array length is...");
- for(let i = 0; i < array.length; i++) {
- array[i] = Math.pow(i, 3)
- arrayString += array[i] + " "
- }
- alert(arrayString)
- }
- // cubes()
- ///////////////////////
- ///////////////
- ////multiply table
- function multiplyTable() {
- var table = [];
- for(let i = 0; i < 10; i++) {
- table[i] = [];
- for(let j = 0; j < 10; j++){
- table[i][j] = ((i) * j)
-
- }
- }
- console.log(table)
- alert(table[5][6])
- alert(table[7][2])
- }
- // multiplyTable()
- //////////////////
- ///////////
- ///matrix to html table
- function matrixTable() {
- var table = [];
- for(let i = 0; i < 10; i++) {
- var newDiv = document.createElement("div");
- table[i] = [];
- for(let j = 0; j < 10; j++){
- var newSpan = document.createElement("span");
- newSpan.style.display = "inline-block";
- newSpan.style.width = "30px"
- table[i][j] = ((i) * j);
- newSpan.innerHTML = table[i][j];
- newDiv.appendChild(newSpan);
- }
- document.body.append(newDiv);
- }
- }
- // matrixTable()
- //////////////////
- ////////////////
- /////blue belt
- function blueBelt() {
- var triangle = "";
- var string = "";
- var sharp = "#";
- var dottRep = 5;
- for(let j = 0; j < 6; j++) {
- var dott = ".";
- dott = dott.repeat(dottRep);
- string += dott + sharp + dott + "\n";
- dottRep = dottRep - 1;
- sharp += "##"
- }
- triangle += string + "\n";
- console.log(triangle)
- }
- // blueBelt()
- /////////////////
- ////////////////
- //blackBelt
- var predictArray = [[-1]];
- var historyArr = [1, 1, 1, 1];
- var myMove = Math.round(Math.random());
- function blackBelt() {
- var yourMove = +prompt("Your move 0 or 1");
- var answer;
- if (yourMove === 1 || yourMove === 0) {
- if (myMove === yourMove){
- answer = confirm("I knew it. Let's try again");
- } else {
- answer = confirm ("You win. Let's try again");
- }
- myMove = predictArray[0][0];
- predictArray = [[historyArr[0]],[historyArr[1]],[historyArr[2]],[historyArr[3]]];
- historyArr.shift();
- historyArr.push(yourMove);
- if(answer == true) {
- return blackBelt()
- }
- } else {
- alert ("Error. Try again")
- }
- }
- // blackBelt();
|