Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
danipoma merged 6 commits intojavascript-tutorial:masterfromotmon76:1.3.2
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
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 deletions1-js/03-code-quality/02-coding-style/1-style-errors/solution.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,48 @@

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

```js no-beautify
functionpow(x,n) // <-no space between arguments
{ // <-figure bracket on a separate line
letresult=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
returnresult;
functionmocnina(x,n) // <-chybí mezera mezi argumenty
{ // <-levá složená závorka na zvláštním řádku
letvý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
returnvý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
functionpow(x, n) {
letresult = 1;
functionmocnina(x, n) {
letvýsledek = 1;

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

returnresult;
returnvý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 deletions1-js/03-code-quality/02-coding-style/1-style-errors/task.md
View file
Open in desktop
Original file line numberDiff line numberDiff 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
functionpow(x,n)
functionmocnina(x,n)
{
letresult=1;
for(let i=0;i<n;i++) {result*=x;}
returnresult;
letvýsledek=1;
for(let i=0;i<n;i++) {výsledek*=x;}
returnvý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

[8]ページ先頭

©2009-2025 Movatter.jp