-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,30 @@ | ||
# Сумма двух чисел | ||
|
||
👶🏻 _Несложная задача_\ | ||
📚 _Закрепление материала_ | ||
|
||
<!--start_statement--> | ||
|
||
Это первая задача курса, которая поможет познакомиться с задачником и процессом сдачи задач. | ||
|
||
В модуле `sum.js` необходимо реализовать функцию `sum`, которая принимает два числа и возвращает их сумму. | ||
|
||
<!--end_statement--> | ||
|
||
--- | ||
|
||
## Инструкция | ||
|
||
📝 Для решения задачи отредактируйте файл: `sum.js`. | ||
|
||
🚀 Команда запуска для ручного тестирования: | ||
```sh | ||
npm run dev | ||
``` | ||
|
||
🔗 Приложение будет доступно на [http://localhost:5173/00-intro/01-sum/](http://localhost:5173/00-intro/01-sum/). | ||
|
||
✅ Доступно автоматическое тестирование: | ||
```sh | ||
npm test sum | ||
``` |
This file contains 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,20 @@ | ||
import { describe, it, expect } from 'vitest' | ||
import { sum } from '@/sum.js' | ||
|
||
describe('intro/sum', () => { | ||
describe('Функция sum', () => { | ||
it('Функция sum должна быть определена', () => { | ||
expect(sum).toBeDefined() | ||
}) | ||
|
||
it.each` | ||
a | b | expected | ||
${1} | ${1} | ${2} | ||
${10} | ${20} | ${30} | ||
${0} | ${0} | ${0} | ||
${-2} | ${-1} | ${-3} | ||
`('Функция sum должна получать $a + $b = $expected', ({a, b, expected}) => { | ||
expect(sum(a, b)).toBe(expected) | ||
}) | ||
}) | ||
}) |
This file contains 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,25 @@ | ||
<!DOCTYPE html> | ||
<html lang="ru"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title></title> | ||
</head> | ||
<body> | ||
<form id="form"> | ||
<p> | ||
<label for="num-a">A:</label> | ||
<input id="num-a" name="num-a" type="number" /> | ||
</p> | ||
<p> | ||
<label for="num-b">B:</label> <input id="num-b" name="num-b" type="number" /> | ||
</p> | ||
<p> | ||
<label> | ||
A + B = | ||
</label> | ||
<output name="result"></output> | ||
</p> | ||
</form> | ||
<script type="module" src="./script.js"></script> | ||
</body> | ||
</html> |
This file contains 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,18 @@ | ||
import { sum } from './sum.js' | ||
|
||
const a = document.querySelector('input[name="num-a"]') | ||
const b = document.querySelector('input[name="num-b"]') | ||
const result = document.querySelector('output[name="result"]') | ||
|
||
function calculate() { | ||
try { | ||
result.value = sum(a.valueAsNumber, b.valueAsNumber) | ||
} catch (e) { | ||
result.value = e.message | ||
} | ||
} | ||
|
||
a.addEventListener('input', calculate) | ||
b.addEventListener('input', calculate) | ||
|
||
document.querySelector('form').addEventListener('submit', (event) => event.preventDefault()) |
This file contains 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,10 @@ | ||
/** | ||
* Вычислить сумму двух чисел | ||
* | ||
* @param {number} a - первое число | ||
* @param {number} b - второе целое | ||
* @return {number} сумма чисел a и b | ||
*/ | ||
export function sum(a, b) { | ||
// Решение | ||
} |
This file contains 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,11 @@ | ||
{ | ||
"extends": "@shgk/vue-course-taskbook/configs/tsconfig.json", | ||
"include": ["**/*", "**/*.vue"], | ||
"files": [], | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"paths": { | ||
"@/*": ["./*"] | ||
} | ||
} | ||
} |