Skip to content

Commit

Permalink
Added task Сумма двух чисел
Browse files Browse the repository at this point in the history
  • Loading branch information
jsru-1 committed Jul 8, 2024
1 parent 8cdd504 commit acc254f
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 0 deletions.
30 changes: 30 additions & 0 deletions 00-intro/10-sum/README.md
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
```
20 changes: 20 additions & 0 deletions 00-intro/10-sum/__tests__/sum.test.ts
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)
})
})
})
25 changes: 25 additions & 0 deletions 00-intro/10-sum/index.html
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>
18 changes: 18 additions & 0 deletions 00-intro/10-sum/script.js
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())
10 changes: 10 additions & 0 deletions 00-intro/10-sum/sum.js
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) {
// Решение
}
11 changes: 11 additions & 0 deletions 00-intro/10-sum/tsconfig.json
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": {
"@/*": ["./*"]
}
}
}

0 comments on commit acc254f

Please sign in to comment.