Giter Site home page Giter Site logo

alco's People

Contributors

alexeykurbako avatar

Watchers

 avatar

alco's Issues

Code Review

Важные замечания

Занеси объявление констант в функцию getrandom() - это позволит быстро изменить диапазон рандома:

alco/alcoJS.js

Lines 35 to 36 in fcc0972

const min=-10;
const max= 10;

Также это упростит данную запись:

alco/alcoJS.js

Lines 37 to 38 in fcc0972

const ch1 = getrandom(min,max);
const ch2 = getrandom(min,max);

Реализуй отдельную функцию:

alco/alcoJS.js

Line 39 in fcc0972

const oper = Math.floor(Math.random()*4);

Объяви константу result и верни ей результат функции result(), имя которой нужно сделать более понятным:

alco/alcoJS.js

Line 41 in fcc0972

if(temp==result(ch1,ch2,oper)){

Лишнее отбрасывание дробной части:

alco/alcoJS.js

Lines 23 to 24 in fcc0972

case 0: return rez = Math.floor(ch1+ch2); break;
case 1: return rez = Math.floor(ch1-ch2); break;

Ненужная функция:

alco/alcoJS.js

Lines 14 to 20 in fcc0972

function prov(ch2,oper){
if(oper==1 && ch2<0){
const sk=1;
return -ch2;
}
return ch2;
}

GRAMMAR NAZI

После служебного слова ставим пробел:

alco/alcoJS.js

Line 34 in fcc0972

while(true){

alco/alcoJS.js

Line 41 in fcc0972

if(temp==result(ch1,ch2,oper)){

Операторы окружаем пробелами:

alco/alcoJS.js

Lines 23 to 26 in fcc0972

case 0: return rez = Math.floor(ch1+ch2); break;
case 1: return rez = Math.floor(ch1-ch2); break;
case 2: return rez = ch1*ch2; break;
case 3: return rez = Math.floor((ch1/ch2)*10)/10; break;

alco/alcoJS.js

Lines 30 to 31 in fcc0972

const result = Math.floor(Math.random()*(max-min))+min;
if(result==0)return max;

alco/alcoJS.js

Line 39 in fcc0972

const oper = Math.floor(Math.random()*4);

Соблюдать правила форматирования кода:

alco/alcoJS.js

Lines 2 to 13 in fcc0972

function operation(oper,ch2){
switch (oper) {
case 0:
//if(ch2<0) return "";
return "+";break;
case 1:
//if(ch2<0) return "+";
return "-";break;
case 2: return "*"; break;
case 3: return "/"; break;
}
}

alco/alcoJS.js

Lines 21 to 28 in fcc0972

function result(ch1,ch2,oper){
switch (oper) {
case 0: return rez = Math.floor(ch1+ch2); break;
case 1: return rez = Math.floor(ch1-ch2); break;
case 2: return rez = ch1*ch2; break;
case 3: return rez = Math.floor((ch1/ch2)*10)/10; break;
}
}

alco/alcoJS.js

Lines 41 to 49 in fcc0972

if(temp==result(ch1,ch2,oper)){
alert('ещё по одной...');
}
else
{
alert('Хватит с тебя');
break;
}
}

Непонятные имена констант:

alco/alcoJS.js

Lines 37 to 38 in fcc0972

const ch1 = getrandom(min,max);
const ch2 = getrandom(min,max);

При перечислении параметров после запятой ставим пробел:
function operation(oper,ch2){

alco/alcoJS.js

Line 21 in fcc0972

function result(ch1,ch2,oper){

alco/alcoJS.js

Line 29 in fcc0972

function getrandom(min,max){

alco/alcoJS.js

Lines 37 to 38 in fcc0972

const ch1 = getrandom(min,max);
const ch2 = getrandom(min,max);

alco/alcoJS.js

Lines 40 to 41 in fcc0972

const temp = prompt(`${ch1}${operation(oper,ch1,ch2)}${ch2}=?`);
if(temp==result(ch1,ch2,oper)){

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.