Repository navigation
add new homework. js2 - #2
romasaldan wants to merge 1 commit into
Conversation
|
|
||
| let distance = 10; | ||
| let totalDistance = distance; | ||
| for ( let day = 1; day < 7; day++ ) { |
There was a problem hiding this comment.
use 2 spaces instead of a tab
| totalDistance = totalDistance + distance; | ||
| } | ||
|
|
||
| totalDistance=totalDistance.toFixed ( 2 ); |
There was a problem hiding this comment.
spaces before and after = and redundant spaces before and after 2
| let naturalNumber = prompt ( 'Please enter a natural number' ) ; | ||
| let dividerOfnaturalNumber; | ||
| if ( naturalNumber == 0) { | ||
| console.log ( "0" ); |
There was a problem hiding this comment.
you can use 0 instead of "0" for console.log. What difference between 0 and '0'?
| console.log ( "0" ); | ||
| } | ||
| for ( let dividerOfnaturalNumber = 1; dividerOfnaturalNumber <= naturalNumber; dividerOfnaturalNumber++ ) { | ||
| ( naturalNumber % dividerOfnaturalNumber == 0 ) |
There was a problem hiding this comment.
use strong equality === instead of ==
| if (numberOfFactorial == 0) { | ||
| console.log ("0! = 1") | ||
| } else if (numberOfFactorial !== 0) { | ||
| function factorial ( numberOfFactorial ) { |
There was a problem hiding this comment.
move factorial out of conditional statement
| if ( numberForPrime == 0 ) { | ||
| console.log (0); | ||
| } else if ( numberForPrime == 1 ) { | ||
| console.log (1); |
There was a problem hiding this comment.
0 and 1 are not Simple number, you must not output this number
| } | ||
| nextPrime: | ||
| for ( let numbersLessOfThis = 2; numbersLessOfThis < numberForPrime; numbersLessOfThis++ ) { | ||
| for ( let numbersLessOfThis2 = 2; numbersLessOfThis2 < numbersLessOfThis; numbersLessOfThis2++ ) { |
There was a problem hiding this comment.
let numbersLessOfThis2, numbersLessOfThis - for variables for iterations in loops you may use i, j as the name of variables
| @@ -0,0 +1,20 @@ | |||
| "use strict" | |||
|
|
|||
| let number = prompt ( 'Please enter a number' ) ; | |||
There was a problem hiding this comment.
when you get value as prompt ( 'Please enter a number' ) ;
you get number as string type, you can add + to make variable number as type number
| console.log ( Math.abs ( divider + ",")); | ||
| } | ||
| } | ||
|
No newline at end of file |
There was a problem hiding this comment.
you can use also equality Math.round(a/b) === a/b if you want to check this
| let valueOfRow3; | ||
| let numberOfRow3=2; | ||
|
|
||
| while ( true ) { |
There was a problem hiding this comment.
it is wrong using of while loop. Instead of true try to use condition 1/numberOfRow < 0.001
No description provided.