Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created arithmetic operators concept, as per #1049 #1420

Merged
merged 34 commits into from
Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
dc83049
As per comment by @benallen in #1049
JaPrad Oct 3, 2021
0d52ab5
Merge branch 'exercism:main' into main
JaPrad Oct 4, 2021
3c53bee
Create about.md
JaPrad Oct 4, 2021
c8a5485
Added Arithmetic Operators concept
JaPrad Oct 4, 2021
1a1e2f3
Added wip status for arithmetic-operators concept
JaPrad Oct 4, 2021
7c812ce
Added uuid for arithmetic-operators concept
JaPrad Oct 5, 2021
5a7036b
Merge branch 'exercism:main' into main
JaPrad Oct 7, 2021
c71a99d
Divided into sections, wrote some comments
JaPrad Oct 7, 2021
ce6a054
Merge branch 'exercism:main' into main
JaPrad Oct 7, 2021
67f560a
Added usage with strings & variables
JaPrad Oct 7, 2021
06cc7bf
Fixed some typos
JaPrad Oct 8, 2021
f0accaf
Added Order of Operations
JaPrad Oct 8, 2021
9d7cf53
Added shorthand assignment operators
JaPrad Oct 8, 2021
98e593e
Create links.json
JaPrad Oct 9, 2021
753a103
Create config.json
JaPrad Oct 9, 2021
8815573
Merge branch 'exercism:main' into main
JaPrad Oct 9, 2021
7f40789
Create introduction.md
JaPrad Oct 9, 2021
2a21309
Added example in shorthand operators
JaPrad Oct 9, 2021
2e5882f
Fixed a typo
JaPrad Oct 9, 2021
b845124
Fixed few typos
JaPrad Oct 9, 2021
fe8ef43
Fixed few typos
JaPrad Oct 9, 2021
a63cca5
Removed string concatenation
JaPrad Oct 10, 2021
8f48582
Removed Incrementation & Decrementation
JaPrad Oct 10, 2021
4e7db59
Removed wip
JaPrad Oct 11, 2021
1d7ae8d
Shortened about & intro
JaPrad Oct 11, 2021
1925314
Clarified shorthand assignment variable examples
JaPrad Oct 11, 2021
6d0d1c2
Followed '1 sentence per line' format
JaPrad Oct 11, 2021
c6b0af5
Changed links from w3schools to javascript.info
JaPrad Oct 11, 2021
a2c9aa9
Fixed a typo
JaPrad Oct 11, 2021
96f740d
Merge branch 'main' of https://github.com/exercism/javascript
JaPrad Oct 11, 2021
e372bfc
add new concept to exercise intoduction
junedev Oct 12, 2021
b69cb1c
some minor improvements
junedev Oct 12, 2021
9b3822d
format
junedev Oct 12, 2021
013fc67
add prettier ignore for calculation example
junedev Oct 12, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions concepts/arithmetic-operators/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"authors": ["JaPatGitHub"],
"contributors": [],
"blurb": "Javascript has 6 different operators to perform basic arithmetic operations on numbers. Additionally there is a matching shorthand assignment operator for each of those."
}
84 changes: 84 additions & 0 deletions concepts/arithmetic-operators/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# About

## Arithmetic Operators

Javascript provides 6 different operators to perform basic arithmetic operations on numbers.

- `+`: The addition operator is used to find sum of numbers.

```javascript
1 + 2; // => 3
2.5 + 3.9; // => 6.5
```

- `-`: The subtraction operator is used to find the difference between two numbers

```javascript
19 - 2; // => 17
7.4 - 1.2; // => 1.5
```

- `*`: The multiplication operator is used to find the product of two numbers two numbers

```javascript
7 * 5; // => 35
9.2 * 6.3; // => 57.959999999999994
```

- `/`: The division operator is used to divide two numbers.
Since JavaScript numbers are always floating point numbers, there is no integer division.

```javascript
8 / 2; // => 4
25 / 3; // => 8.333333333333334
```

- `%`: The remainder operator is used to find the remainder of a division performed.

```javascript
40 % 4; // => 0
11 % 4; // => 3
-11 % 4; // => -3
```

- `**`: The exponentiation operator is used to raise a number to a power.
It is the equivalent of using [`Math.pow()`][mdn-math-pow]

```javascript
4 ** 3; // => 62
4 ** 1 / 2; // => 2
```

## Order of Operations

When using multiple operators in a line, JavaScript follows an order of precedence as shown in [this precedence table][mdn-operator-precedence].
To simplify it to our context, JavaScript uses the PEDMAS (Parentheses, Exponents, Division/Multiplication, Addition/Subtraction) rule we've leant in elementary math classes.

<!-- prettier-ignore-start -->
```javascript
const result = 3 ** 3 + 9 * 4 / (3 - 1);
// => 3 ** 3 + 9 * 4/2
// => 27 + 9 * 4/2
// => 27 + 18
// => 45
```
<!-- prettier-ignore-end -->

## Shorthand Assignment Operators

Shorthand assignment operators are a shorter way of writing code conducting arithmetic operations on a variable, and assigning the new value to the same variable.
For example, consider two variables `x` and `y`.
Then, `x += y` is same as `x = x + y`.
Often, this is used with a number instead of a variable `y`.
The 5 other operations can also be conducted in a similar style.

```javascript
let x = 5;
x += 25; // x is now 30

let y = 31;
y %= 3; // y is now 1
```

[mdn-math-pow]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow
[mdn-operator-precedence]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#table
62 changes: 62 additions & 0 deletions concepts/arithmetic-operators/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Introduction

## Arithmetic Operators

Javascript provides 6 different operators to perform basic arithmetic operations on numbers.

- `+`: The addition operator is used to find sum of numbers.
- `-`: The subtraction operator is used to find the difference between two numbers
- `*`: The multiplication operator is used to find the product of two numbers.
- `/`: The division operator is used to divide two numbers.

```javascript
2 - 1.5; //=> 0.5
19 / 2; //=> 9.5
```

- `%`: The remainder operator is used to find the remainder of a division performed.

```javascript
40 % 4; // => 0
-11 % 4; // => -3
```

- `**`: The exponentiation operator is used to raise a number to a power.

```javascript
4 ** 3; // => 62
4 ** 1 / 2; // => 2
```

## Order of Operations

When using multiple operators in a line, JavaScript follows an order of precedence as shown in [this precedence table][mdn-operator-precedence].
To simplify it to our context, JavaScript uses the PEDMAS (Parentheses, Exponents, Division/Multiplication, Addition/Subtraction) rule we've leant in elementary math classes.

<!-- prettier-ignore-start -->
```javascript
const result = 3 ** 3 + 9 * 4 / (3 - 1);
// => 3 ** 3 + 9 * 4/2
// => 27 + 9 * 4/2
// => 27 + 18
// => 45
```
<!-- prettier-ignore-end -->

## Shorthand Assignment Operators

Shorthand assignment operators are a shorter way of writing code conducting arithmetic operations on a variable, and assigning the new value to the same variable.
For example, consider two variables `x` and `y`.
Then, `x += y` is same as `x = x + y`.
Often, this is used with a number instead of a variable `y`.
The 5 other operations can also be conducted in a similar style.

```javascript
let x = 5;
x += 25; // x is now 30

let y = 31;
y %= 3; // y is now 1
```

[mdn-operator-precedence]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#table
14 changes: 14 additions & 0 deletions concepts/arithmetic-operators/links.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"url": "https://javascript.info/operators#maths",
"description": "javascript.info: Arithmetic Operators"
},
{
"url": "https://javascript.info/operators#modify-in-place",
"description": "javascript.info: Shorthand Assignment Operators"
},
{
"url": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence",
"description": "MDN: Operator Precedence"
}
]
7 changes: 6 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"slug": "freelancer-rates",
"name": "Freelancer Rates",
"uuid": "0aff2fa7-55ea-47e9-af4a-78927d916baf",
"concepts": ["numbers"],
"concepts": ["numbers", "arithmetic-operators"],
"prerequisites": ["basics"],
"status": "beta"
},
Expand Down Expand Up @@ -1626,6 +1626,11 @@
]
},
"concepts": [
{
"uuid": "82329ca4-62a6-4df4-be44-73cecc21e1b8",
"slug": "arithmetic-operators",
"name": "Arithmetic Operators"
},
{
"uuid": "e1b15569-387c-4833-8c3b-9a94e0ee1583",
"slug": "array-analysis",
Expand Down
2 changes: 1 addition & 1 deletion exercises/concept/freelancer-rates/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ We first establish a few rules between the freelancer and the project manager:
- The daily rate is 8 times the hourly rate;
- A month has 22 billable days.

If the freelancer bills the project manager per month, there is a discount applied. This can be handy if the project manager has a fixed budget.
If the freelancer bills the project manager per month or more, there is a discount applied. This can be handy if the project manager has a fixed budget.

Discounts are modeled as fractional numbers (percentage) between `0.0` (`0%`, no discount) and `0.90` (`90%`, maximum discount).

Expand Down
63 changes: 63 additions & 0 deletions exercises/concept/freelancer-rates/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Introduction

## Numbers

Many programming languages have specific numeric types to represent different types of numbers, but JavaScript only has two:

- `number`: a numeric data type in the double-precision 64-bit floating point format (IEEE 754).
Expand All @@ -9,3 +11,64 @@ Many programming languages have specific numeric types to represent different ty

If you require arbitrary precision or work with extremely large numbers, use the `bigint` type.
Otherwise, the `number` type is likely the better option.

## Arithmetic Operators

Javascript provides 6 different operators to perform basic arithmetic operations on numbers.

- `+`: The addition operator is used to find sum of numbers.
- `-`: The subtraction operator is used to find the difference between two numbers
- `*`: The multiplication operator is used to find the product of two numbers.
- `/`: The division operator is used to divide two numbers.

```javascript
2 - 1.5; //=> 0.5
19 / 2; //=> 9.5
```

- `%`: The remainder operator is used to find the remainder of a division performed.

```javascript
40 % 4; // => 0
-11 % 4; // => -3
```

- `**`: The exponentiation operator is used to raise a number to a power.

```javascript
4 ** 3; // => 62
4 ** 1 / 2; // => 2
```

### Order of Operations

When using multiple operators in a line, JavaScript follows an order of precedence as shown in [this precedence table][mdn-operator-precedence].
To simplify it to our context, JavaScript uses the PEDMAS (Parentheses, Exponents, Division/Multiplication, Addition/Subtraction) rule we've leant in elementary math classes.

<!-- prettier-ignore-start -->
```javascript
const result = 3 ** 3 + 9 * 4 / (3 - 1);
// => 3 ** 3 + 9 * 4/2
// => 27 + 9 * 4/2
// => 27 + 18
// => 45
```
<!-- prettier-ignore-end -->

### Shorthand Assignment Operators

Shorthand assignment operators are a shorter way of writing code conducting arithmetic operations on a variable, and assigning the new value to the same variable.
For example, consider two variables `x` and `y`.
Then, `x += y` is same as `x = x + y`.
Often, this is used with a number instead of a variable `y`.
The 5 other operations can also be conducted in a similar style.

```javascript
let x = 5;
x += 25; // x is now 30

let y = 31;
y %= 3; // y is now 1
```

[mdn-operator-precedence]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#table