-
Notifications
You must be signed in to change notification settings - Fork 0
Hw7 #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NosovDima
wants to merge
13
commits into
master
Choose a base branch
from
hw7
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Hw7 #12
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
cebb27a
hm4 done
NosovDima c297cfd
hw4 is done
NosovDima b3feedf
hw4 edited
NosovDima b593b7f
hw5 almost done
NosovDima ecb03bf
hm5 done
NosovDima ebdf76e
hw5_edited
NosovDima 9f9d0d7
HW5completed
NosovDima d26147f
hw6
NosovDima d414b1f
hw6 completed
NosovDima 8741c0a
hw 6 edited
NosovDima db12d1c
hw7
NosovDima b920b08
hw7 edited
NosovDima a65de32
7hw done
NosovDima File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| function wordsGame() { | ||
| let arr = [ | ||
| "Яблоко", | ||
| "Груша", | ||
| "Дыня", | ||
| "Виноград", | ||
| "Персик", | ||
| "Апельсин", | ||
| "Мандарин", | ||
| ]; | ||
| arr = arr.sort(() => Math.random() - 0.5); | ||
| alert(arr); | ||
| let userAnswer1 = prompt("Чему равнялся первый элемент массива?"); | ||
| let userAnswer2 = prompt("Чему равнялся первый элемент массива?"); | ||
| if ( | ||
| userAnswer1.toLowerCase() == arr[0].toLowerCase() && | ||
| userAnswer2.toLowerCase() == arr[6].toLowerCase() | ||
| ) { | ||
| alert("Поздравляем, Вы угадили!"); | ||
| } else if ( | ||
| userAnswer1.toLowerCase() == arr[0].toLowerCase() || | ||
| userAnswer2.toLowerCase() == arr[6].toLowerCase() | ||
| ) { | ||
| alert("Вы были близки к победе!"); | ||
| } else { | ||
| alert("Все ответы неверные"); | ||
| } | ||
| } | ||
| wordsGame(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| // Exercise 1 | ||
| const least = (a, b) => { | ||
| if (a < b) { | ||
| return a; | ||
| } else { | ||
| return b; | ||
| } | ||
| }; | ||
| console.log(least(4, 8)); | ||
| console.log(least(6, 6)); | ||
| // or | ||
| function min(a, b) { | ||
| return a < b ? a : b; | ||
| } | ||
| console.log(min(4, 8)); | ||
| // Exercise 2 | ||
| const evenNum = (a) => { | ||
| if (a % 2 == 0) { | ||
| return "Четное число"; | ||
| } else { | ||
| return "Нечетное число"; | ||
| } | ||
| // Как сделать с prompt? | ||
| }; | ||
| alert(evenNum(7)); | ||
| or | ||
|
|
||
| let number = prompt("Введите число"); | ||
|
|
||
| if (number % 2 == 0) { | ||
| function evenNum() { | ||
| alert("Четное число"); | ||
| } | ||
| } else { | ||
| function evenNum() { | ||
| alert("Нечетное число"); | ||
| } | ||
| } | ||
| evenNum(); | ||
| // or | ||
| function evenNum(a) { | ||
| return a % 2 == 0 ? "Четное число" : "Нечетное число"; | ||
| } | ||
| alert(evenNum(7)); | ||
| // Exercise 3.2 | ||
| const squareNum = (a) => { | ||
| let result = a ** 2; | ||
| return result; | ||
| }; | ||
| console.log(squareNum(3)); | ||
| // Exercise 3.1 | ||
| let number = prompt("Введите число"); | ||
| function squareNum(a) { | ||
| return a ** 2; | ||
| } | ||
| alert(squareNum(Number)); | ||
| // Exercise 4 | ||
| let age = prompt("Сколько Вам лет?"); | ||
| if (age < 0) { | ||
| function printMessage() { | ||
| alert("Вы ввели неправильное значение"); | ||
| } | ||
| } else if (age < 12) { | ||
| function printMessage() { | ||
| alert("Привет, друг!"); | ||
| } | ||
| } else { | ||
| function printMessage() { | ||
| alert("Добро пожаловать!"); | ||
| } | ||
| } | ||
| { | ||
| } | ||
| printMessage(); | ||
| // Exercise 5 | ||
| const mult = (a, b) => { | ||
| if (isNaN(a) || isNaN(b)) { | ||
| return "Одно или оба значения не являются числом"; | ||
| } | ||
| let result = a * b; | ||
| return result; | ||
| }; | ||
| alert(mult(prompt("Введите первое число"), prompt("Введите второе число"))); | ||
|
|
||
| // // Exercise 6 | ||
| const mult = (a) => { | ||
| if (isNaN(a)) { | ||
| return "Значение не является числом"; | ||
| } | ||
| let result = a ** 3; | ||
| return result; | ||
| }; | ||
| alert(mult(prompt("Введите первое число"))); | ||
| // Exercise 7 | ||
| function getСircleArea() { | ||
| return this.radius ** 2 * Math.PI; | ||
| } | ||
| function getСirclePerimeter() { | ||
| return this.radius * 2 * Math.PI; | ||
| } | ||
|
|
||
| const circle1 = { | ||
| radius: 3, | ||
|
|
||
| getArea: getСircleArea, | ||
| getPerimeter: getСirclePerimeter, | ||
| }; | ||
|
|
||
| const circle2 = { | ||
| radius: 7, | ||
|
|
||
| getArea: getСircleArea, | ||
| getPerimeter: getСirclePerimeter, | ||
| }; | ||
|
|
||
| alert(circle1.getArea()); | ||
| alert(circle1.getPerimeter()); | ||
| alert(circle2.getArea()); | ||
| alert(circle2.getPerimeter()); | ||
| // Exercise 8 | ||
| const season = (a) => { | ||
| if (isNaN(a)) { | ||
| return "Вы ввели не число"; | ||
| } | ||
| if (a == 12 || (a >= 1 && a <= 2)) { | ||
| // Ошибка в синтаксисе? Не видит число 12 | ||
| return "Зима"; | ||
| } else if (a >= 3 && a <= 5) { | ||
| return "Весна"; | ||
| } else if (a >= 6 && a <= 8) { | ||
| return "Лето"; | ||
| } else if (a >= 9 && a <= 11) { | ||
| return "Осень"; | ||
| } else { | ||
| return "Такого месяца не существует"; | ||
| } | ||
| { | ||
| } | ||
| { | ||
| } | ||
| { | ||
| } | ||
| }; | ||
| alert(season(prompt("Введите номер месяца"))); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| const newspaper = { | ||
| sports: { | ||
| title: "ARod Hits Home Run", | ||
| writers: ["Miramon Nuevo", "Rick Reilly", "Woddy Paige"], | ||
| }, | ||
| business: { | ||
| title: "GE Stock Dips Again", | ||
| writers: ["Adam Smith", "Albert Humphrey", "Charles Handy"], | ||
| }, | ||
| movies: { | ||
| title: "Superman Is A Flop", | ||
| writers: ["Rogert Ebert", "Andrew Sarris", "Wesley Morris"], | ||
| }, | ||
| }; | ||
| newspaper.sports.title; | ||
| newspaper.business.writers[0]; | ||
| newspaper.movies.writers[1]; | ||
| // Exersice 1 | ||
| const numbers = [1, 5, 4, 10, 0, 3]; | ||
|
|
||
| for (let i = 0; i < numbers.length; i++) { | ||
| alert(numbers[i]); | ||
| if (numbers[i] === 10) break; | ||
|
|
||
| } | ||
|
|
||
| // Exersice 2 | ||
| const numbers = [1, 5, 4, 10, 0, 3]; | ||
| alert(numbers.indexOf(4)); | ||
| // Exersice 3 | ||
| let numbers = [1, 3, 5, 10, 20]; | ||
| numbers = numbers.join(" "); | ||
| alert(numbers); | ||
| // Exersice 4 | ||
|
|
||
| const arr = []; | ||
| for (let i = 0; i < 3; i++) { | ||
| arr[i] = []; | ||
| for (let a = 0; a < 3; a++) { | ||
| arr[i][a] = 1; | ||
| } | ||
| } | ||
| alert(arr); | ||
| // Exersice 5 | ||
| let numbers = [1, 1, 1]; | ||
| numbers.push(2, 2, 2); | ||
| alert(numbers); | ||
| // Exercise 6 | ||
| let arrNum = [9, 8, 7, "a", 6, 5]; | ||
| arrNum = arrNum.sort(); | ||
| arrNum.pop(); | ||
| alert(arrNum); | ||
| // Exersice 7 | ||
| const numbers = [9, 8, 7, 6, 5]; | ||
| let num = Number(prompt("Пожалуйста, введите любое число")); | ||
| let search = numbers.includes(num); | ||
| alert(numbers.includes(num)); | ||
| // Exersice 8 | ||
| let letters = "abcdef"; | ||
| letters = letters.split(""); | ||
| letters.sort(); | ||
| letters.reverse(); | ||
| letters = letters.join(" "); | ||
| alert(letters); | ||
| // Exersice 9 | ||
| let arrNum = [ | ||
| [1, 2, 3], | ||
| [4, 5, 6], | ||
| ]; | ||
| for (let item of arrNum) { | ||
| item = item.join(" "); | ||
| } | ||
| alert(arrNum); | ||
| // Exersice 10 | ||
| const arr = [9, 8, 7, 6, 5]; | ||
| for (let i = 0; i < arr.length - 1; i++) { | ||
| alert(arr[i] + arr[i + 1]); | ||
| } | ||
| // Exersice 11 | ||
| const num = [ | ||
| prompt("Пожалуйста, введите любое число"), | ||
| prompt("Пожалуйста, введите любое число"), | ||
| prompt("Пожалуйста, введите любое число"), | ||
| prompt("Пожалуйста, введите любое число"), | ||
| ]; | ||
| const squareNum = num.map((el) => el ** 2); | ||
| alert(squareNum); | ||
| // Exersice 12 | ||
| function getLengthWords(words) { | ||
| return words.map((item) => item.length); | ||
| } | ||
| alert(getLengthWords(prompt("Введите слово"))); | ||
| // Exersice 13 | ||
| function filterPositive(array) { | ||
| return array.filter((el) => el > 0); | ||
| } | ||
|
|
||
| filterPositive([-1, 0, 5, -10, 56]); // => [-1, -10] | ||
| filterPositive([-25, 25, 0, -1000, -2]); // => [-25, -1000, -2] | ||
| // Exersice 14 | ||
| const arr = [...Array(10)].map((e) => ~~(Math.random() * 10)); | ||
| const evenNum = arr.filter((el) => el % 2 == 0); | ||
| alert(evenNum); | ||
| alert(arr); | ||
| // Exersice 15 | ||
|
|
||
| const average = (arr) => arr.reduce((a, b) => a + b, 0) / arr.length; | ||
| const result = average([...Array(6)].map((e) => ~~(Math.random() * 6))); | ||
| alert(result); | ||
| alert(average); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alert(evenNum(prompt('введите число')));