Skip to content

add new homework. js2 - #2

Open
romasaldan wants to merge 1 commit into
masterfrom
develop
Open

romasaldan wants to merge 1 commit into
masterfrom
develop

Conversation

@romasaldan

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread js_hw2/js1.js

let distance = 10;
let totalDistance = distance;
for ( let day = 1; day < 7; day++ ) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use 2 spaces instead of a tab

Comment thread js_hw2/js1.js
totalDistance = totalDistance + distance;
}

totalDistance=totalDistance.toFixed ( 2 );

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spaces before and after = and redundant spaces before and after 2

Comment thread js_hw2/js2.js
let naturalNumber = prompt ( 'Please enter a natural number' ) ;
let dividerOfnaturalNumber;
if ( naturalNumber == 0) {
console.log ( "0" );

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use 0 instead of "0" for console.log. What difference between 0 and '0'?

Comment thread js_hw2/js2.js
console.log ( "0" );
}
for ( let dividerOfnaturalNumber = 1; dividerOfnaturalNumber <= naturalNumber; dividerOfnaturalNumber++ ) {
( naturalNumber % dividerOfnaturalNumber == 0 )

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use strong equality === instead of ==

Comment thread js_hw2/js3.js
if (numberOfFactorial == 0) {
console.log ("0! = 1")
} else if (numberOfFactorial !== 0) {
function factorial ( numberOfFactorial ) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move factorial out of conditional statement

Comment thread js_hw2/js5.js
if ( numberForPrime == 0 ) {
console.log (0);
} else if ( numberForPrime == 1 ) {
console.log (1);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 and 1 are not Simple number, you must not output this number

Comment thread js_hw2/js5.js
}
nextPrime:
for ( let numbersLessOfThis = 2; numbersLessOfThis < numberForPrime; numbersLessOfThis++ ) {
for ( let numbersLessOfThis2 = 2; numbersLessOfThis2 < numbersLessOfThis; numbersLessOfThis2++ ) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let numbersLessOfThis2, numbersLessOfThis - for variables for iterations in loops you may use i, j as the name of variables

Comment thread js_hw2/js6.js
@@ -0,0 +1,20 @@
"use strict"

let number = prompt ( 'Please enter a number' ) ;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread js_hw2/js6.js
console.log ( Math.abs ( divider + ","));
}
}

No newline at end of file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use also equality Math.round(a/b) === a/b if you want to check this

Comment thread js_hw2/js9.js
let valueOfRow3;
let numberOfRow3=2;

while ( true ) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is wrong using of while loop. Instead of true try to use condition 1/numberOfRow < 0.001

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant