-
Notifications
You must be signed in to change notification settings - Fork 0
Lesson 1-3 #1
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
base: main
Are you sure you want to change the base?
Lesson 1-3 #1
Changes from all commits
9f6ba21
9d1a4fc
dc1ad5c
031ebcc
1a60928
081de3e
6a3f688
dd6fc11
943dd00
6024b07
64281eb
39c8d98
de2073d
f236c4e
3344193
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| const Tc = 36.6; | ||
| const Tf = (9 / 5) * Tc + 32; | ||
| alert(Tf); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| const name = "Василий"; | ||
| const admin = name; | ||
| alert(admin); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| // Значение будет равно 1000108 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| var a = 1, b = 1, c, d; | ||
| c = ++a; alert(c); // 2 : Инкремунет(увеличивает значение переменной на 1) | ||
| d = b++; alert(d); // 1 : Инкремунет(увеличивает значение переменной на 1) | ||
| c = (2+ ++a); alert(c); // 5 : 2 + Инкремент переменной a(2 + 3) | ||
| d = (2+ b++); alert(d); // 4 : 2 + Инкремент переменной b | ||
| alert(a); // 3 : Увеличение значение во 2-ой строчке и в 4-ой | ||
| alert(b); // 3 : Увеличение значение во 3-ей строчке и в 5-ой |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| var a = 2; | ||
| var x = 1 + (a *= 2); | ||
| /* | ||
| x = 1 + (2*2) = 5 | ||
| a = 4 | ||
| */ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| var a = prompt("Введите a"); | ||
| var b = prompt("Введите b"); | ||
| if (a >= 0 && b >= 0) { | ||
| alert("Разность: " + Math.abs(a - b)); | ||
| } else if (a < 0 && b < 0) { | ||
| alert("Произведение: "(a * b)); | ||
| } else { | ||
| alert("Сумма: " + ( Number(a) + Number(b))); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| const a = prompt('Введите число в промежутке [0, 15].'); | ||
| switch (a) { | ||
| case '0': | ||
| for(let i = Number(a); i <= 15; i++) { | ||
| console.log(i); | ||
| } | ||
| break; | ||
|
|
||
| case '1': | ||
| for(let i = Number(a); i <= 15; i++) { | ||
| console.log(i); | ||
| } | ||
| break; | ||
|
|
||
| case '2': | ||
| for(let i = Number(a); i <= 15; i++) { | ||
| console.log(i); | ||
| } | ||
| break; | ||
|
|
||
| case '3': | ||
| for(let i = Number(a); i <= 15; i++) { | ||
| console.log(i); | ||
| } | ||
| break; | ||
|
|
||
| case '4': | ||
| for(let i = Number(a); i <= 15; i++) { | ||
| console.log(i); | ||
| } | ||
| break; | ||
|
|
||
| case '5': | ||
| for(let i = Number(a); i <= 15; i++) { | ||
| console.log(i); | ||
| } | ||
| break; | ||
|
|
||
| case '6': | ||
| for(let i = Number(a); i <= 15; i++) { | ||
| console.log(i); | ||
| } | ||
| break; | ||
|
|
||
| case '7': | ||
| for(let i = Number(a); i <= 15; i++) { | ||
| console.log(i); | ||
| } | ||
| break; | ||
|
|
||
| case '8': | ||
| for(let i = Number(a); i <= 15; i++) { | ||
| console.log(i); | ||
| } | ||
| break; | ||
|
|
||
| case '9': | ||
| for(let i = Number(a); i <= 15; i++) { | ||
| console.log(i); | ||
| } | ||
| break; | ||
|
|
||
| case '10': | ||
| for(let i = Number(a); i <= 15; i++) { | ||
| console.log(i); | ||
| } | ||
| break; | ||
|
|
||
| case '11': | ||
| for(let i = Number(a); i <= 15; i++) { | ||
| console.log(i); | ||
| } | ||
| break; | ||
|
|
||
| case '12': | ||
| for(let i = Number(a); i <= 15; i++) { | ||
| console.log(i); | ||
| } | ||
| break; | ||
|
|
||
| case '13': | ||
| for(let i = Number(a); i <= 15; i++) { | ||
| console.log(i); | ||
| } | ||
| break; | ||
|
|
||
| case '14': | ||
| for(let i = Number(a); i <= 15; i++) { | ||
| console.log(i); | ||
| } | ||
| break; | ||
|
|
||
| case '15': | ||
| for(let i = Number(a); i <= 15; i++) { | ||
| console.log(i); | ||
| } | ||
| break; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| function sum(a, b) { | ||
| return a + b; | ||
| } | ||
|
|
||
| function subtract(a, b) { | ||
| return a - b; | ||
| } | ||
|
|
||
| function multiply(a, b) { | ||
| return a * b; | ||
| } | ||
|
|
||
| function divide(a, b) { | ||
| return a / b; | ||
| } | ||
|
|
||
| var a = prompt("Введите 1-ое число."); | ||
| var operation = prompt("Введите операцию(+, -, *, /)."); | ||
| var b = prompt("Введите 2-ое число."); | ||
|
|
||
| switch (operation) { | ||
| case "+": | ||
| alert( sum(Number(a), Number(b))); | ||
| break; | ||
|
|
||
| case "-": | ||
| alert( subtract(Number(a), Number(b))); | ||
| break; | ||
|
|
||
| case "*": | ||
| alert( multiply(Number(a), Number(b))); | ||
| break; | ||
|
|
||
| case "/": | ||
| alert( divide(Number(a), Number(b))); | ||
| break; | ||
|
|
||
| default: | ||
| alert("Допускаемые операции (+, -, *, /)."); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| function mathOperation(a, b, operation) { | ||
| switch (operation) { | ||
| case "+": | ||
| return a + b; | ||
| break; | ||
|
|
||
| case "-": | ||
| return a - b; | ||
| break; | ||
|
|
||
| case "*": | ||
| return a * b | ||
| break; | ||
|
|
||
| case "/": | ||
| return a / b; | ||
| break; | ||
|
|
||
| default: | ||
| alert("Допускаемые операции (+, -, *, /).") | ||
| } | ||
|
Comment on lines
+4
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. забыли про функции из задания выше There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. break при наличии return не нужен |
||
| } | ||
|
|
||
| var a = prompt("Введите 1-ое число."); | ||
| var operation = prompt("Введите операцию(+, -, *, /)."); | ||
| var b = prompt("Введите 2-ое число."); | ||
|
|
||
| alert("Result: " + mathOperation( Number(a), Number(b), operation)); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| function power(val, pow) { | ||
| if (pow == 1) { | ||
| return val; | ||
| } else { | ||
| return val * power(val, pow - 1); | ||
| } | ||
| } | ||
|
|
||
| var val = prompt("Введите число."); | ||
| var pow = prompt("Введите степень."); | ||
|
|
||
| alert("Result: " + power( Number(val), Number(pow))); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| var a = []; | ||
| var lst = []; | ||
|
|
||
| for (let i = 0; i <= 100; i++) { | ||
| a.push(i); | ||
| } | ||
|
|
||
| a[1] = 0; | ||
| i = 2; | ||
|
|
||
| while (i <= 100) { | ||
| if (a[i] != 0) { | ||
| lst.push(a[i]); | ||
| let j = i | ||
|
|
||
| while (j <= 100) { | ||
| a[j] = 0; | ||
| j += i | ||
| } | ||
| } | ||
| i++; | ||
| } | ||
|
|
||
| console.log(lst); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| var count = prompt("Введите количество товаров."); | ||
| var cart = []; | ||
|
|
||
| for (let i = 0; i < count; i++) { | ||
| let product = []; | ||
| product.push( prompt("Введите ID товара.")); | ||
| product.push( prompt("Введите стоимость товара.")); | ||
| product.push( prompt("Введите количество товара.")); | ||
| cart.push(product); | ||
| } | ||
|
|
||
| var sum = 0; | ||
|
|
||
| for (let i = 0; i < cart.length; i++) { | ||
| sum += Number(cart[i][2]) * Number(cart[i][1]); | ||
| } | ||
|
Comment on lines
+14
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. нужно было написать функцию |
||
| alert("Итого: " + sum); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| for (let i = 0; i <= 9; console.log(i), i++) {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| var pyramid = "*" | ||
| for (let i = 1; i <= 20; i++) { | ||
| console.log(pyramid) | ||
| pyramid += "*" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| # JavaScript | ||
| # JavaScript | ||
| Доброго времени суток :) | ||
| На уроках 1 и 2 за домашки у меня стоят заглушки, поэтому объединяю все 3 дз в один ПР. |
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.
задача была только средствами свиты/кейс, цикл не трогаем