Skip to content

Coding Style #97

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

Merged
merged 6 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions 1-js/03-code-quality/02-coding-style/1-style-errors/solution.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@

You could note the following:
Měli byste si všimnout následujícího:

```js no-beautify
function pow(x,n) // <- no space between arguments
{ // <- figure bracket on a separate line
let result=1; // <- no spaces before or after =
for(let i=0;i<n;i++) {result*=x;} // <- no spaces
// the contents of { ... } should be on a new line
return result;
function mocnina(x,n) // <- chybí mezera mezi argumenty
{ // <- levá složená závorka na zvláštním řádku
let výsledek=1; // <- chybějí mezery před a za =
for(let i=0;i<n;i++) {výsledek*=x;} // <- chybějí mezery
// obsah { ... } by měl být na novém řádku
return výsledek;
}

let x=prompt("x?",''), n=prompt("n?",'') // <-- technically possible,
// but better make it 2 lines, also there's no spaces and missing ;
if (n<=0) // <- no spaces inside (n <= 0), and should be extra line above it
{ // <- figure bracket on a separate line
// below - long lines can be split into multiple lines for improved readability
alert(`Power ${n} is not supported, please enter an integer number greater than zero`);
let x=prompt("x?",''), n=prompt("n?",'') // <-- technicky je to možné,
// ale lepší je to rozdělit na 2 řádky, navíc tam chybějí mezery a ;
if (n<=0) // <- chybějí mezery uvnitř (n <= 0) a nad ním by měl být prázdný řádek
{ // <- levá složená závorka na zvláštním řádku
// níže - dlouhé řádky by měly být rozděleny na více řádků pro lepší čitelnost
alert(`${n}-tá mocnina není podporována, zadejte prosím celé číslo větší než nula`);
}
else // <- could write it on a single line like "} else {"
else // <- toto může být na jediném řádku: "} else {"
{
alert(pow(x,n)) // no spaces and missing ;
alert(mocnina(x,n)) // chybějí mezery a ;
}
```

The fixed variant:
Opravená varianta:

```js
function pow(x, n) {
let result = 1;
function mocnina(x, n) {
let výsledek = 1;

for (let i = 0; i < n; i++) {
result *= x;
výsledek *= x;
}

return result;
return výsledek;
}

let x = prompt("x?", "");
let n = prompt("n?", "");

if (n <= 0) {
alert(`Power ${n} is not supported,
please enter an integer number greater than zero`);
alert(`${n}-tá mocnina není podporována,
zadejte prosím celé číslo větší než nula`);
} else {
alert( pow(x, n) );
alert( mocnina(x, n) );
}
```
18 changes: 9 additions & 9 deletions 1-js/03-code-quality/02-coding-style/1-style-errors/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ importance: 4

---

# Bad style
# Špatný styl

What's wrong with the code style below?
Co je špatného na stylu níže uvedeného kódu?

```js no-beautify
function pow(x,n)
function mocnina(x,n)
{
let result=1;
for(let i=0;i<n;i++) {result*=x;}
return result;
let výsledek=1;
for(let i=0;i<n;i++) {výsledek*=x;}
return výsledek;
}

let x=prompt("x?",''), n=prompt("n?",'')
if (n<=0)
{
alert(`Power ${n} is not supported, please enter an integer number greater than zero`);
alert(`${n}-tá mocnina není podporována, zadejte prosím celé číslo větší než nula`);
}
else
{
alert(pow(x,n))
alert(mocnina(x,n))
}
```

Fix it.
Opravte ho.
Loading