Skip to content

Commit ea28f07

Browse files
authored
Merge pull request #61 from laurentiu798/master
Coding Style
2 parents 91c903b + 3f60ce0 commit ea28f07

File tree

3 files changed

+129
-120
lines changed

3 files changed

+129
-120
lines changed

1-js/03-code-quality/02-coding-style/1-style-errors/solution.md

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11

2-
You could note the following:
2+
Man kann Folgendes anmerken:
33

44
```js no-beautify
5-
function pow(x,n) // <- no space between arguments
6-
{ // <- figure bracket on a separate line
7-
let result=1; // <- no spaces before or after =
8-
for(let i=0;i<n;i++) {result*=x;} // <- no spaces
9-
// the contents of { ... } should be on a new line
5+
function pow(x,n) // <- kein Leerzeichen zwischen Parametern
6+
{ // <- Klammer auf in eine zweite Zeile
7+
let result=1; // <- keine Leerzeichen vor und nach =
8+
for(let i=0;i<n;i++) {result*=x;} // <- keine Leerzeichen
9+
// the contents of { ... } sollte in eine neue Zeile sein
1010
return result;
1111
}
1212

13-
let x=prompt("x?",''), n=prompt("n?",'') // <-- technically possible,
14-
// but better make it 2 lines, also there's no spaces and missing ;
15-
if (n<=0) // <- no spaces inside (n <= 0), and should be extra line above it
16-
{ // <- figure bracket on a separate line
17-
// below - long lines can be split into multiple lines for improved readability
18-
alert(`Power ${n} is not supported, please enter an integer number greater than zero`);
13+
14+
let x=prompt("x?",''), n=prompt("n?",'') // <-- theoretisch möglich,
15+
// aber besser wenn man es auf zwei Zeilen aufteilt. Es fehlen auch die Leerzeichen und das Semikolon ;
16+
if (n<0) // <- keine Leerzeichen in den Klammern (n < 0), davor sollte auch eine leere Zeile sein
17+
{ // <- Klammer auf in eine neue Zeile
18+
// unten - lange Zeilen können aufgeteilt werden um die Lesbarkeit zu verbessern
19+
alert(`Exponent ${n} wird nicht unterstützt, bitte geben Sie einen Integerwert ein, der größer ist als null`);
20+
1921
}
20-
else // <- could write it on a single line like "} else {"
22+
else // <- man könnte es in einer einzigen Zeile schreiben "} else {"
2123
{
22-
alert(pow(x,n)) // no spaces and missing ;
24+
alert(pow(x,n)) // keine Leerzeichen und kein ;
2325
}
2426
```
2527

26-
The fixed variant:
28+
Die Verbesserte Variante:
2729

2830
```js
2931
function pow(x, n) {
@@ -39,9 +41,11 @@ function pow(x, n) {
3941
let x = prompt("x?", "");
4042
let n = prompt("n?", "");
4143

42-
if (n <= 0) {
43-
alert(`Power ${n} is not supported,
44-
please enter an integer number greater than zero`);
44+
45+
if (n < 0) {
46+
alert(`Exponent ${n} wird nicht unterstützt,
47+
bitte geben Sie einen Integerwert ein, der größer ist als null`);
48+
4549
} else {
4650
alert( pow(x, n) );
4751
}

1-js/03-code-quality/02-coding-style/1-style-errors/task.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ importance: 4
22

33
---
44

5-
# Bad style
5+
# Schlechter Stil
66

7-
What's wrong with the code style below?
7+
Was ist an dem Codestil unten falsch?
88

99
```js no-beautify
1010
function pow(x,n)
@@ -17,12 +17,12 @@ function pow(x,n)
1717
let x=prompt("x?",''), n=prompt("n?",'')
1818
if (n<=0)
1919
{
20-
alert(`Power ${n} is not supported, please enter an integer number greater than zero`);
20+
alert(`Exponent ${n} wird nicht unterstützt, bitte geben Sie einen Integerwert ein, der größer als 0 ist`);
2121
}
2222
else
2323
{
2424
alert(pow(x,n))
2525
}
2626
```
2727

28-
Fix it.
28+
Verbessere ihn.

0 commit comments

Comments
 (0)