This commit is contained in:
Ilya Kantor 2017-02-23 19:03:14 +03:00
parent 20784e7f26
commit 7019d1470d
48 changed files with 1019 additions and 464 deletions

View file

@ -1,50 +1,48 @@
# Ответ
Вы могли заметить следующие недостатки, сверху-вниз:
You could note the following:
```js no-beautify
function pow(x,n) // <- отсутствует пробел между аргументами
{ // <- фигурная скобка на отдельной строке
var result=1; // <- нет пробелов вокруг знака =
for(var i=0;i<n;i++) {result*=x;} // <- нет пробелов
// содержимое скобок { ... } лучше вынести на отдельную строку
function pow(x,n) // <- no space between arguments
{ // <- figure bracket on a separate line
let result=1; // <- no spaces to the both sides of =
for(let i=0;i<n;i++) {result*=x;} // <- no spaces
// the contents of { ... } should be on a new line
return result;
}
x=prompt("x?",'') // <- не объявлена переменная, нет пробелов, ;
n=prompt("n?",'')
if (n<0) // <- нет пробелов, стоит добавить вертикальную отбивку
{ // <- фигурная скобка на отдельной строке
// ниже - слишком длинная строка, нет пробелов
alert('Степень '+n+'не поддерживается, введите целую степень, большую 0');
let x=prompt("x?",''), n=prompt("n?",'') // <-- technically possible,
// but better make it 2 lines, also there's no spaces and ;
if (n<0) // <- no spaces inside (n < 0), and should be extra line above it
{ // <- figure bracket on a separate line
// below - a long line, may be worth to split into 2 lines
alert(`Power ${n} is not supported, please enter an integer number greater than zero`);
}
else // <- можно на одной строке } else {
else // <- could write it on a single line like "} else {"
{
alert(pow(x,n)) // нет точки с запятой
alert(pow(x,n)) // no spaces and ;
}
```
Исправленный вариант:
The fixed variant:
```js
function pow(x, n) {
var result = 1;
let result = 1;
for (var i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
result *= x;
}
return result;
}
var x = prompt("x?", "");
var n = prompt("n?", "");
let x = prompt("x?", "");
let n = prompt("n?", "");
if (n < 0) {
alert('Степень ' + n +
'не поддерживается, введите целую степень, большую 0');
alert(`Power ${n} is not supported,
please enter an integer number greater than zero`);
} else {
alert( pow(x, n) );
}
```

View file

@ -2,23 +2,22 @@ importance: 4
---
# Ошибки в стиле
# Bad style
Какие недостатки вы видите в стиле этого примера?
What's wrong with the code style below?
```js no-beautify
function pow(x,n)
{
var result=1;
for(var i=0;i<n;i++) {result*=x;}
let result=1;
for(let i=0;i<n;i++) {result*=x;}
return result;
}
x=prompt("x?",'')
n=prompt("n?",'')
let x=prompt("x?",''), n=prompt("n?",'')
if (n<=0)
{
alert('Степень '+n+'не поддерживается, введите целую степень, большую 0');
alert(`Power ${n} is not supported, please enter an integer number greater than zero`);
}
else
{
@ -26,3 +25,4 @@ else
}
```
Fix it.