ToCode Solution: תרגול JavaScript Syntax#1
ToCode Solution: תרגול JavaScript Syntax#1shlomitha wants to merge 1 commit intoynonp:masterfrom shlomitha:sol-html5-web-development.javascript-syntax-lab
Conversation
ynonp
left a comment
There was a problem hiding this comment.
Hi,
Please see comments and submit fixed files
Thanks,
Ynon
| function lcm(a, b) { | ||
| } | ||
|
|
||
| //function 1 |
There was a problem hiding this comment.
Please leave the top comments in the file and functions (the ones inside /* */). They make it easier for everyone opening the file later to understand what's inside
|
|
||
|
|
||
| function printBiggestNumber(){ | ||
| var max=100; |
There was a problem hiding this comment.
Re. var:
- Some people prefer to use just one
varcommand, i.e. (note line ends with,not in;):
var max = 100,
min = 0,
first_num = Math.floor((Math.random() * max) + min);
- Modern browsers (everything except IE) support 2 new keywords:
letandconst. Take a moment to read about both here:
https://strongloop.com/strongblog/es6-variable-declarations/ - Style: JavaScript variables and functions are usually written in camel case (like Java), so firstNum is better than first_num
- Style: I'd define a function randomInRange(min, max), and then use that instead of repeating the calculation
| var secound_num=Math.floor((Math.random() * max) + min); | ||
| var third_num=Math.floor((Math.random() * max) + min); | ||
|
|
||
| console.log("first_num ="+ first_num); |
There was a problem hiding this comment.
If you're using modern (non-IE) browsers, you can also use the newer string interpolation syntax:
console.log(`first num = ${first_num}`);
Notice the backticks (same button as ~ but without holding the shift)
| console.log("secound_num ="+ secound_num); | ||
| console.log("third_num ="+ third_num); | ||
|
|
||
| var max_number=Math.max(first_num, secound_num,third_num); |
| var max=1000; | ||
| var min=9999; | ||
| var num=Math.floor((Math.random() * max) + min); | ||
| num=""+num; |
There was a problem hiding this comment.
While that does convert num to a string, it indicates bad style and hurts readability (some people may even get a wrong impression about JS seeing such code).
Better to use the more readable num = String(num)
|
|
||
| //Least Common Multiple | ||
| function printLCM(x,y) { | ||
| var lcm= (x*y) / calcGCD(x,y); |
No description provided.