Skip to content

Commit 84fa8cc

Browse files
committed
Minor fixes.
1 parent b7ac703 commit 84fa8cc

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

JavaScript-Quick-Reference.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -1007,10 +1007,11 @@ A floating-point number includes decimal parts, allowing for the representation
10071007

10081008
### parseInt(string, radix)
10091009

1010-
The `parseInt()` function in JavaScript is used to convert a string to an integer (whole number). It takes two parameters:
1011-
- The string to be converted (which should represent a number)
1010+
The `parseInt()` function in JavaScript is used to convert a string to an integer (whole number). It takes two parameters:
1011+
1012+
- The string to be converted (which should represent a number)
10121013
- The base (or radix) of the numerical system to which the string belongs
1013-
1014+
10141015
When using `parseInt()`, it's crucial to specify the radix to ensure accurate conversion.
10151016

10161017
- For decimal numbers (the usual number system), use base 10.
@@ -1114,7 +1115,6 @@ Essential guide to JavaScript's Math object, covering basic constants and mathem
11141115

11151116
- `Math.random()` is a JavaScript method that generates a floating-point, pseudo-random number in the range from 0 (inclusive) to 1 (exclusive). This means it can return a number as small as 0 but never exactly 1.
11161117

1117-
11181118
```javascript
11191119
// Function to get a random choice for the computer
11201120
function getComputerChoice() {
@@ -1136,7 +1136,6 @@ console.log(`Computer chose: ${computerSelection}`);
11361136

11371137
The function getComputerChoice() utilizes Math.random() to simulate making a random choice between 'rock', 'paper', and 'scissors'. By comparing the random number against fractional thresholds, it assigns one of these three choices. This is a straightforward use case where Math.random() directly influences the flow of the program based on random selection.
11381138

1139-
11401139
### Math.trunc
11411140

11421141
Math.trunc is a method in JavaScript's Math object that is used to remove the decimal part of a number, effectively truncating it to an integer. This method does not round the number; it simply cuts off the decimal portion.
@@ -2183,10 +2182,12 @@ console.log(randomItem); // Randomly selected item
21832182
```
21842183

21852184
### Math.trunc
2186-
- Math.trunc can be paired with Math.random() for generating zero-based index values, useful in selecting random elements from an array. For example, Math.trunc(Math.random() * array.length) can randomly index into an array, ensuring the index starts at 0 and is within the array bounds.
2185+
2186+
- Math.trunc can be paired with Math.random() for generating zero-based index values, useful in selecting random elements from an array. For example, Math.trunc(Math.random() \* array.length) can randomly index into an array, ensuring the index starts at 0 and is within the array bounds.
21872187

21882188
### Math.floor
2189-
- Math.floor, on the other hand, can be utilized with Math.random() to create inclusive upper-bound random integers. For instance, Math.floor(Math.random() * (max - min + 1)) + min generates a random integer between min and max, inclusively, catering to situations where the starting integer is 1 and the upper limit must be part of the outcome range.
2189+
2190+
- Math.floor, on the other hand, can be utilized with Math.random() to create inclusive upper-bound random integers. For instance, Math.floor(Math.random() \* (max - min + 1)) + min generates a random integer between min and max, inclusively, catering to situations where the starting integer is 1 and the upper limit must be part of the outcome range.
21902191

21912192
### Advanced Applications
21922193

0 commit comments

Comments
 (0)