Skip to content

Commit a3bd033

Browse files
author
juanantonioledesma
committed
Add "Multiplication table for number" kata
1 parent ce0facb commit a3bd033

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<h1>Multiplication table for number <sup><sup>8 Kyu</sup></sup></h1>
2+
3+
<sup>
4+
<a href="https://www.codewars.com/kata/5a2fd38b55519ed98f0000ce">
5+
<strong>LINK TO THE KATA</strong>
6+
</a> - <code>FUNDAMENTALS</code> <code>STRINGS</code>
7+
</sup>
8+
9+
## Description
10+
11+
Your goal is to return multiplication table for `number` that is always an integer from 1 to 10.
12+
13+
For example, a multiplication table (string) for `number == 5` looks like below:
14+
15+
```
16+
1 * 5 = 5
17+
2 * 5 = 10
18+
3 * 5 = 15
19+
4 * 5 = 20
20+
5 * 5 = 25
21+
6 * 5 = 30
22+
7 * 5 = 35
23+
8 * 5 = 40
24+
9 * 5 = 45
25+
10 * 5 = 50
26+
```
27+
28+
P. S. You can use `\n` in string to jump to the next line.
29+
30+
Note: newlines should be added between rows, but there should be no trailing newline at the end. If you're unsure about the format, look at the sample tests.
31+
32+
## Solution
33+
34+
```javascript
35+
const multiTable = number => {
36+
let result = ''
37+
38+
for (let i = 1; i <= 10; i++) {
39+
const multiplication = `${i} * ${number} = ${i * number}`
40+
result += i === 10 ? multiplication : `${multiplication}\n`
41+
}
42+
43+
return result
44+
}
45+
```

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ JavaScript katas on Codewars are programming challenges that help you improve yo
7373
## 8 kyu
7474

7575
- **[Is your period late?](./8-kyu/is-your-period-late.md)**
76+
- **[Multiplication table for number](./8-kyu/multiplication-table-for-number.md)**
7677
- **[Multiply](./8-kyu/multiply.md)**
7778
- **[Object Oriented Piracy](./8-kyu/object-oriented-piracy.md)**
7879
- **[Opposites Attract](./8-kyu/opposites-attract.md)**

0 commit comments

Comments
 (0)