123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <script>
- /// Я тут почти все обернула в функции, чтобы при проверке не переключать кучу алертов.
- //Number: age
- function year (age) {
- var yearBorn;
- var today = new Date();
- var year = today.getFullYear();
- age = prompt ("How old are you?");
- yearBorn = year - age;
- alert ("The year when you're born is " + yearBorn)
- }
- // year()
- //
- //Number: temperature
- function temperature (firstTemperature) {
- var yourResult;
- firstTemperature = prompt ("How many degrees?")
- if (isNaN (firstTemperature)) {
- return alert ("Error. Please write a numver")
- }
- secondTemperature()
- function secondTemperature (styleof) {
- styleOf = prompt ("What kind of calculus scale of temperature it is?(celsius or fahrenheit)");
- if (styleOf == "fahrenheit") {
- yourResult = Math.round((firstTemperature - 32) * 5/9);
- return alert ("Your result is " + yourResult)
- }
- else if (styleOf == "celsius") {
- yourResult = Math.round((firstTemperature * 9/5) + 32);
- return alert ("Your result is " + yourResult)
- } else {
- alert ("Please chose celsius of fahrenheit calculus scale.")
- return secondTemperature()
- }
- }
- }
- // temperature()
- //
- // Number: divide
- function divide (first, second) {
- var result;
- first = prompt ("Please chose your first numver.");
- if (isNaN (first)) {
- return alert ("Error. Please write a numver")
- }
- second = prompt ("Please chose your second number.");
- if (isNaN (second)) {
- return alert ("Error. Please write a numver")
- }
- result = Math.round(first / second);
- return alert ("Your result is " + result);
- }
- // divide ()
- //
- //Number: odd
- function numberOdd (question) {
- question = +prompt("Give me your number");
- if (isNaN (question)) {
- return alert ("Error. Please write a number");
- } else if (question % 2 == 0) {
- return alert ("Even number")
- } else {
- return alert ("Odd number")
- }
- }
- // numberOdd ()
- //
- //String: greeting
- function greeting (name) {
- name = prompt ("What is your name?");
- return alert ("Hello, " + name)
- }
- // greeting ()
- //
- //String: lexics
- function lexics (string) {
- string = prompt ("Напишите свое отчество?");
- if (string.indexOf("вна") === -1 && string.indexOf("вич") === -1) {
- alert ("Вы уверены?")
- } else {
- return alert ("Красивое ;)")
- }
- }
- // lexics ()
- //
- //confirm
- function whatConfirm (object) {
- object = confirm ("Push the button please");
- alert ("Confirm returns " + typeof(object))
- }
- //Возвращает true или false (смотря какую кнопку нажать) - булевый тип данных
- // whatConfirm()
- //
- //Boolean
- // Boolean if
- function whoYouAre (male, age, animal, music) {
- male = confirm ("Are you a woman?");
- if (male == true) {
- male = "woman";
- } else {
- male = "men";
- }
- age = confirm ("Are you older than 35 years old?");
- if (age == true) {
- age = "several age";
- } else {
- age = "young";
- }
- animal = confirm ("Do you like cats more than dogs?");
- if (animal == true) {
- animal = "cats";
- } else {
- animal = "dogs";
- }
- music = confirm ("Do you like classical music?");
- if (music == true) {
- music = "like";
- } else {
- music = " don't like";
- }
- alert ("You're " + age + " " + male + " who prefer " + animal + " and " + music + " classical music.")
- }
- // whoYouAre ()
- //
- // Array: real
- // серии сериальчиков, продукты в холодильнике, одежда в шкафу.
- //
- // Array: booleans
- var male = "woman";
- var age = 26;
- var animal = "dogs";
- var music = "classical";
- var arrayBooleans = [male, age, animal, music];
- //
- // Array: plus
- var arrayPlus = [12, 16, 18, 20];
- function massivePlus (result) {
- result = arrayPlus[0] + arrayPlus[1];
- arrayPlus[2] = result;
- alert ( arrayPlus)
- return alert (arrayPlus[2])
- }
- // massivePlus()
- // после этой функции 2й индекс массива замещается новым значением. При этом предыдущее значение не сдвигается, а исчезаетв
- //Array: plus string
- var arrayPlusString = ["12", "16", "18", "20"];
- function massivePlusString (result) {
- result = arrayPlusString[0] + arrayPlusString[1] + arrayPlusString[2]
- arrayPlusString[2] = result;
- alert ( arrayPlusString)
- return alert (arrayPlusString[2])
- }
- // massivePlusString()
- //Возможно это пригодится при создании дат, номеров телефонов и прочего? Если в том же prompt будут вводить строки из цифр.
- //
- //Object: real
- {
- var dog = {
- name: "Vero",
- breed: "german shepherd",
- type: "shorthaired",
- age: 3,
- toys: ["ball", "bone", "knot"]
- }
- }
- //
- //Object: change
- function dog() {
- var dog = {
- name: "Vero",
- breed: "german shepherd",
- type: "shorthaired",
- age: 3,
- toys: ["bone", "knot", "ball"]
- }
- alert ("Vero's " + dog.age + " years old")
- dog.age = 4;
- alert ("Oups, now Vero's " + dog.age + " years old");
- alert ("Her favorite toys are " + dog.toys[0] + ", " + dog.toys[1] + ", and " + dog.toys[2])
- dog.toys.pop()
- dog.toys.push("wheel")
- alert ("She broked a one toy. So her favorite toys are " + dog.toys[0] + ", " + dog.toys[1] + ", and " + dog.toys[2] + " now")
- }
- // dog()
- //
- //Comparison if
- function comparisonIf () {
- var age = +prompt("Сколько вам лет?","");
- if (age <= 0) {
- alert ("Простите, но мне кажется вы врете -_-")
- }
- else if ((age > 0) && (age <= 18)) {
- alert("школьник");
- }
- else if ((age > 18) && (age <= 30)){
- alert("молодеж");
- }
- else if ((age > 30) && (age <= 45)){
- alert("зрелость");
- }
- else if ((age > 45) && (age <= 60)){
- alert("закат");
- }
- else if (age >= 60){
- alert("как пенсия?");
- }
- else {
- alert("то ли киборг, то ли ошибка");
- }
- }
- // comparisonIf()
- // это я добавила скобки, насколько поняла
- function comparisonIfSecond () {
- var age = +prompt("Сколько вам лет?","");
- if (age <= 0) {
- alert ("Простите, но мне кажется вы врете -_-")
- }
- else if (age <= 18) {
- alert("школьник");
- }
- else if (age <= 30) {
- alert("молодеж");
- }
- else if (age <= 45) {
- alert("зрелость");
- }
- else if (age <= 60 ) {
- alert("закат");
- }
- else if (age > 60) {
- alert("как пенсия?");
- }
- else {
- alert("то ли киборг, то ли ошибка");
- }
- }
- /////
- ///Comparison: sizes
- ///Comparison: object
- function searchSize (styleWear, firstMassive, firstSize) {
- sizeWear = {
- russia: [40, 42, 44, 46, 48, 50, 52, 54],
- USA: ["S", "M", "M", "L", "L", "XL", "XL", "XXL"]
- }
- womanSize = {
- russia: [42 ,44, 46, 48, 50, 52, 54, 56],
- USA: ["XXS", "XS", "S", "M", "L", "XL", "XXL", "XXXL"]
- }
- sizeStockings = {
- russia: [21, 21, 23, 23, 25, 25, 27],
- USA: [8, 8.5, 9, 9.5, 10, 10.5, 11]
- }
- styleWear = prompt("What size chart do you need?(dress/outerwear/pants - 1, lingerie - 2, tights/stockings - 3");
- if (styleWear === "1") {
- styleWear = sizeWear
- firstMassive = sizeWear.russia
- } else if (styleWear === "2") {
- styleWear = womanSize
- firstMassive = womanSize.russia
- } else if (styleWear === "3") {
- styleWear = sizeStockings
- firstMassive = sizeStockings.russia
- } else {
- return alert ("Error. Please try again")
- }
- firstSize = +prompt("Please give me your size in Russia/Urkaine style");
- firstSize = firstMassive.indexOf(firstSize)
- if (firstSize == -1) {
- return alert("Error. Please check your data")
- }
- alert ("Your size in USA chart is " + styleWear.USA[firstSize])
- }
- // searchSize()
- ////
- ///Ternary
- (confirm ("Are you a woman?")) ? alert("You're woman") : alert("You're man")
- </script>
- </head>
- <body>
-
- </body>
- </html>
|