commit 4b2868343e5f8660c143fc65522ed432342b39df Author: Fedorov Vladimir Date: Mon Jan 9 19:51:43 2023 +0700 add topic_1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/topic_1/script.js b/topic_1/script.js new file mode 100644 index 0000000..114ec81 --- /dev/null +++ b/topic_1/script.js @@ -0,0 +1,125 @@ +console.log("Задание 1 ----------"); +let hello = "Hello world!"; +let message; +message = hello; +console.log(hello, message); + +console.log("Задание 2 ----------"); +function auto(x1, x2, s1, t) { + let speed = x1 + x2; + let s2 = speed * t; + let endS = s1 - s2; + if (endS < 0) { + return -endS; + } + return endS; +} +console.log(auto(5, 5, 50, 6)); + +console.log("Задание 3.1 ----------"); +function f3(a, b) { + if (a < b) { + return a + b; + } + if (a > b) { + return a - b; + } + return a * b; +} +console.log(f3(1,2)); +console.log(f3(2,1)); +console.log(f3(2,2)); + +console.log("Задание 3.2 ----------"); +function f3_2(num) { + switch(num) { + case 1: + return "зима" + case 2: + return "весна" + case 3: + return "лето" + case 4: + return "осень" + default: + return "Кто ты такой?" + } +} +console.log(f3_2(1)); +console.log(f3_2(2)); +console.log(f3_2(3)); +console.log(f3_2(4)); +console.log(f3_2(5)); + +console.log("Задание 4.1 ----------"); +for (var i = 1; i <= 100; i++) { + console.log(i); +} +console.log("Задание 4.2 ----------"); +for (var i = 11; i <= 33; i++) { + console.log(i); +} +console.log("Задание 4.2 ----------"); +let sum = 0; +for (var i = 1; i <= 100; i++) { + sum += i; +} +console.log(sum); + +console.log("Задание 5 ----------"); +function f5(s) { + return s === s.split("").reverse().join("") +} +console.log(f5("hello")); +console.log(f5("ollo")); + +console.log("Задание 6 ----------"); +function len(s1, s2) { + return s1.length + s2.length +} +console.log(len("hello", "world")); + +console.log("Задание 7.1 ----------"); +console.log([1,2,3].concat([4,5,6])); +console.log("Задание 7.2 ----------"); +console.log([1,2,3].reverse()); +console.log("Задание 7.3 ----------"); +let arr7_3 = [1,2,3] +arr7_3.push(4,5,6) +console.log(arr7_3); +console.log("Задание 7.4 ----------"); +let arr7_4 = [1,2,3] +arr7_4.unshift(4,5,6) +console.log(arr7_4); +console.log("Задание 7.5 ----------"); +console.log(['js', 'css', 'jq'][0]); +console.log("Задание 7.6 ----------"); +let arr7_6 = ['js', 'css', 'jq'] +let last = arr7_6[arr7_6.length - 1] +console.log(last); +console.log("Задание 7.7 ----------"); +let arr7_7 = [1,2,3,4,5] +let a7_7 = arr7_7.slice(0,3) +console.log(a7_7); +let b7_7 = arr7_7.slice(3,5) +console.log(b7_7); +console.log("Задание 7.8 ----------"); +let arr7_8_1 = [1,2,3,4,5] +arr7_8_1.splice(1, 2) +console.log(arr7_8_1); +let arr7_8_2 = [1,2,3,4,5] +arr7_8_2.splice(5, 0, 2, 3, 4) +console.log(arr7_8_2); +console.log("Задание 7.9 ----------"); +console.log([3, 4, 1, 2, 7].sort()); + +console.log("Задание 8.1 ----------"); +function f8_1(a, b) { + return Math.pow(a, b); +} +console.log(f8_1(2,3)); +console.log("Задание 8.2 ----------"); +function f8_2(a, b, round) { + return a * b * Math.sin(round / 180 * Math.PI) / 2; +} +console.log(f8_2(2, 3, 90));