2.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <script>
  8. /// Я тут почти все обернула в функции, чтобы при проверке не переключать кучу алертов.
  9. //Number: age
  10. function year (age) {
  11. var yearBorn;
  12. var today = new Date();
  13. var year = today.getFullYear();
  14. age = prompt ("How old are you?");
  15. yearBorn = year - age;
  16. alert ("The year when you're born is " + yearBorn)
  17. }
  18. // year()
  19. //
  20. //Number: temperature
  21. function temperature (firstTemperature) {
  22. var yourResult;
  23. firstTemperature = prompt ("How many degrees?")
  24. if (isNaN (firstTemperature)) {
  25. return alert ("Error. Please write a numver")
  26. }
  27. secondTemperature()
  28. function secondTemperature (styleof) {
  29. styleOf = prompt ("What kind of calculus scale of temperature it is?(celsius or fahrenheit)");
  30. if (styleOf == "fahrenheit") {
  31. yourResult = Math.round((firstTemperature - 32) * 5/9);
  32. return alert ("Your result is " + yourResult)
  33. }
  34. else if (styleOf == "celsius") {
  35. yourResult = Math.round((firstTemperature * 9/5) + 32);
  36. return alert ("Your result is " + yourResult)
  37. } else {
  38. alert ("Please chose celsius of fahrenheit calculus scale.")
  39. return secondTemperature()
  40. }
  41. }
  42. }
  43. // temperature()
  44. //
  45. // Number: divide
  46. function divide (first, second) {
  47. var result;
  48. first = prompt ("Please chose your first numver.");
  49. if (isNaN (first)) {
  50. return alert ("Error. Please write a numver")
  51. }
  52. second = prompt ("Please chose your second number.");
  53. if (isNaN (second)) {
  54. return alert ("Error. Please write a numver")
  55. }
  56. result = Math.round(first / second);
  57. return alert ("Your result is " + result);
  58. }
  59. // divide ()
  60. //
  61. //Number: odd
  62. function numberOdd (question) {
  63. question = +prompt("Give me your number");
  64. if (isNaN (question)) {
  65. return alert ("Error. Please write a number");
  66. } else if (question % 2 == 0) {
  67. return alert ("Even number")
  68. } else {
  69. return alert ("Odd number")
  70. }
  71. }
  72. // numberOdd ()
  73. //
  74. //String: greeting
  75. function greeting (name) {
  76. name = prompt ("What is your name?");
  77. return alert ("Hello, " + name)
  78. }
  79. // greeting ()
  80. //
  81. //String: lexics
  82. function lexics (string) {
  83. string = prompt ("Напишите свое отчество?");
  84. if (string.indexOf("вна") === -1 && string.indexOf("вич") === -1) {
  85. alert ("Вы уверены?")
  86. } else {
  87. return alert ("Красивое ;)")
  88. }
  89. }
  90. // lexics ()
  91. //
  92. //confirm
  93. function whatConfirm (object) {
  94. object = confirm ("Push the button please");
  95. alert ("Confirm returns " + typeof(object))
  96. }
  97. //Возвращает true или false (смотря какую кнопку нажать) - булевый тип данных
  98. // whatConfirm()
  99. //
  100. //Boolean
  101. // Boolean if
  102. function whoYouAre (male, age, animal, music) {
  103. male = confirm ("Are you a woman?");
  104. if (male == true) {
  105. male = "woman";
  106. } else {
  107. male = "men";
  108. }
  109. age = confirm ("Are you older than 35 years old?");
  110. if (age == true) {
  111. age = "several age";
  112. } else {
  113. age = "young";
  114. }
  115. animal = confirm ("Do you like cats more than dogs?");
  116. if (animal == true) {
  117. animal = "cats";
  118. } else {
  119. animal = "dogs";
  120. }
  121. music = confirm ("Do you like classical music?");
  122. if (music == true) {
  123. music = "like";
  124. } else {
  125. music = " don't like";
  126. }
  127. alert ("You're " + age + " " + male + " who prefer " + animal + " and " + music + " classical music.")
  128. }
  129. // whoYouAre ()
  130. //
  131. // Array: real
  132. // серии сериальчиков, продукты в холодильнике, одежда в шкафу.
  133. //
  134. // Array: booleans
  135. var male = "woman";
  136. var age = 26;
  137. var animal = "dogs";
  138. var music = "classical";
  139. var arrayBooleans = [male, age, animal, music];
  140. //
  141. // Array: plus
  142. var arrayPlus = [12, 16, 18, 20];
  143. function massivePlus (result) {
  144. result = arrayPlus[0] + arrayPlus[1];
  145. arrayPlus[2] = result;
  146. alert ( arrayPlus)
  147. return alert (arrayPlus[2])
  148. }
  149. // massivePlus()
  150. // после этой функции 2й индекс массива замещается новым значением. При этом предыдущее значение не сдвигается, а исчезаетв
  151. //Array: plus string
  152. var arrayPlusString = ["12", "16", "18", "20"];
  153. function massivePlusString (result) {
  154. result = arrayPlusString[0] + arrayPlusString[1] + arrayPlusString[2]
  155. arrayPlusString[2] = result;
  156. alert ( arrayPlusString)
  157. return alert (arrayPlusString[2])
  158. }
  159. // massivePlusString()
  160. //Возможно это пригодится при создании дат, номеров телефонов и прочего? Если в том же prompt будут вводить строки из цифр.
  161. //
  162. //Object: real
  163. {
  164. var dog = {
  165. name: "Vero",
  166. breed: "german shepherd",
  167. type: "shorthaired",
  168. age: 3,
  169. toys: ["ball", "bone", "knot"]
  170. }
  171. }
  172. //
  173. //Object: change
  174. function dog() {
  175. var dog = {
  176. name: "Vero",
  177. breed: "german shepherd",
  178. type: "shorthaired",
  179. age: 3,
  180. toys: ["bone", "knot", "ball"]
  181. }
  182. alert ("Vero's " + dog.age + " years old")
  183. dog.age = 4;
  184. alert ("Oups, now Vero's " + dog.age + " years old");
  185. alert ("Her favorite toys are " + dog.toys[0] + ", " + dog.toys[1] + ", and " + dog.toys[2])
  186. dog.toys.pop()
  187. dog.toys.push("wheel")
  188. alert ("She broked a one toy. So her favorite toys are " + dog.toys[0] + ", " + dog.toys[1] + ", and " + dog.toys[2] + " now")
  189. }
  190. // dog()
  191. //
  192. //Comparison if
  193. function comparisonIf () {
  194. var age = +prompt("Сколько вам лет?","");
  195. if (age <= 0) {
  196. alert ("Простите, но мне кажется вы врете -_-")
  197. }
  198. else if ((age > 0) && (age <= 18)) {
  199. alert("школьник");
  200. }
  201. else if ((age > 18) && (age <= 30)){
  202. alert("молодеж");
  203. }
  204. else if ((age > 30) && (age <= 45)){
  205. alert("зрелость");
  206. }
  207. else if ((age > 45) && (age <= 60)){
  208. alert("закат");
  209. }
  210. else if (age >= 60){
  211. alert("как пенсия?");
  212. }
  213. else {
  214. alert("то ли киборг, то ли ошибка");
  215. }
  216. }
  217. // comparisonIf()
  218. // это я добавила скобки, насколько поняла
  219. function comparisonIfSecond () {
  220. var age = +prompt("Сколько вам лет?","");
  221. if (age <= 0) {
  222. alert ("Простите, но мне кажется вы врете -_-")
  223. }
  224. else if (age <= 18) {
  225. alert("школьник");
  226. }
  227. else if (age <= 30) {
  228. alert("молодеж");
  229. }
  230. else if (age <= 45) {
  231. alert("зрелость");
  232. }
  233. else if (age <= 60 ) {
  234. alert("закат");
  235. }
  236. else if (age > 60) {
  237. alert("как пенсия?");
  238. }
  239. else {
  240. alert("то ли киборг, то ли ошибка");
  241. }
  242. }
  243. /////
  244. ///Comparison: sizes
  245. ///Comparison: object
  246. function searchSize (styleWear, firstMassive, firstSize) {
  247. sizeWear = {
  248. russia: [40, 42, 44, 46, 48, 50, 52, 54],
  249. USA: ["S", "M", "M", "L", "L", "XL", "XL", "XXL"]
  250. }
  251. womanSize = {
  252. russia: [42 ,44, 46, 48, 50, 52, 54, 56],
  253. USA: ["XXS", "XS", "S", "M", "L", "XL", "XXL", "XXXL"]
  254. }
  255. sizeStockings = {
  256. russia: [21, 21, 23, 23, 25, 25, 27],
  257. USA: [8, 8.5, 9, 9.5, 10, 10.5, 11]
  258. }
  259. styleWear = prompt("What size chart do you need?(dress/outerwear/pants - 1, lingerie - 2, tights/stockings - 3");
  260. if (styleWear === "1") {
  261. styleWear = sizeWear
  262. firstMassive = sizeWear.russia
  263. } else if (styleWear === "2") {
  264. styleWear = womanSize
  265. firstMassive = womanSize.russia
  266. } else if (styleWear === "3") {
  267. styleWear = sizeStockings
  268. firstMassive = sizeStockings.russia
  269. } else {
  270. return alert ("Error. Please try again")
  271. }
  272. firstSize = +prompt("Please give me your size in Russia/Urkaine style");
  273. firstSize = firstMassive.indexOf(firstSize)
  274. if (firstSize == -1) {
  275. return alert("Error. Please check your data")
  276. }
  277. alert ("Your size in USA chart is " + styleWear.USA[firstSize])
  278. }
  279. // searchSize()
  280. ////
  281. ///Ternary
  282. (confirm ("Are you a woman?")) ? alert("You're woman") : alert("You're man")
  283. </script>
  284. </head>
  285. <body>
  286. </body>
  287. </html>