Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

version: 2
updates:
- package-ecosystem: "npm" # See documentation for possible values
directory: "/" # Location of package manifests
- package-ecosystem: 'npm' # See documentation for possible values
directory: '/' # Location of package manifests
schedule:
interval: "weekly"
interval: 'weekly'

- package-ecosystem: "github-actions"
- package-ecosystem: 'github-actions'
# Workflow files stored in the
# default location of `.github/workflows`
directory: "/"
directory: '/'
schedule:
interval: "weekly"
interval: 'weekly'
2 changes: 1 addition & 1 deletion .github/workflows/standard-criteria-tests.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Standard Criteria
on:
pull_request:
branches: [ main ]
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
Expand Down
4 changes: 0 additions & 4 deletions .husky/pre-commit

This file was deleted.

5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,23 @@
## Instructions

- Read through the numbered comments in the following files to understand the requirements of this exercise.

- `src/boolean-conditions.js`
- `src/numeric-conditions.js`
- `src/string-conditions.js`
- `src/multiple-conditions.js`

- Write your code directly below the numbered comment.

- Add `console.log()`s to get visibility on your solution and run the file with the command `node src/<file>.js` *etc*
- Add `console.log()`s to get visibility on your solution and run the file with the command `node src/<file>.js` _etc_

- See `src/example.js` for some examples

## Running tests

- To verify your solutions, run the test suite by running the `npx jasmine` command followed by the path to the corresponding test file for each `src/*.js` file above, eg:

`npx jasmine spec/boolean-conditions.spec.js`
`npx jasmine spec/boolean-conditions.spec.js`

- Alternatively, run:

Expand Down
22 changes: 12 additions & 10 deletions spec/string-conditions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,18 @@ describe('answerSeven', () => {
})

describe('answerEight', () => {
const seasons = {
Winter: ['December', 'January', 'February'],
Autumn: ['September', 'October', 'November'],
Summer: ['June', 'July', 'August'],
Spring: ['March', 'April', 'May']
}
const seasons = {
Winter: ['December', 'January', 'February'],
Autumn: ['September', 'October', 'November'],
Summer: ['June', 'July', 'August'],
Spring: ['March', 'April', 'May']
}

const expected = Object.keys(seasons).find(season => seasons[season].includes(MONTH))
const expected = Object.keys(seasons).find((season) =>
seasons[season].includes(MONTH)
)

it(`should be '${expected}'`, () => {
expect(answerEight).toEqual(expected)
})
it(`should be '${expected}'`, () => {
expect(answerEight).toEqual(expected)
})
})
19 changes: 7 additions & 12 deletions spec/support/all-jasmine.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.?(m)js"
],
"helpers": [
"helpers/**/*.?(m)js"
],
"env": {
"stopSpecOnExpectationFailure": false,
"random": true
}
"spec_dir": "spec",
"spec_files": ["**/*[sS]pec.?(m)js"],
"helpers": ["helpers/**/*.?(m)js"],
"env": {
"stopSpecOnExpectationFailure": false,
"random": true
}
}
19 changes: 7 additions & 12 deletions spec/support/extensions-jasmine.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
{
"spec_dir": "spec",
"spec_files": [
"extensions/**/*[sS]pec.?(m)js"
],
"helpers": [
"helpers/**/*.?(m)js"
],
"env": {
"stopSpecOnExpectationFailure": false,
"random": true
}
"spec_dir": "spec",
"spec_files": ["extensions/**/*[sS]pec.?(m)js"],
"helpers": ["helpers/**/*.?(m)js"],
"env": {
"stopSpecOnExpectationFailure": false,
"random": true
}
}
9 changes: 2 additions & 7 deletions spec/support/jasmine.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.?(m)js",
"!extensions/**"
],
"helpers": [
"helpers/**/*.?(m)js"
],
"spec_files": ["**/*[sS]pec.?(m)js", "!extensions/**"],
"helpers": ["helpers/**/*.?(m)js"],
"env": {
"stopSpecOnExpectationFailure": false,
"random": true
Expand Down
118 changes: 63 additions & 55 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,81 +15,89 @@ But more commonly we can also store the result of a comparison:

```javascript
const myBool = 5 > 3 //myBool will be set to true
myBool
>>> false
myBool >>> false
```

Rather than comparing fixed numbers like 3 and 5, we can also compare variables:

```javascript
const age = 10
const isOver18 = age > 18 //isOver18 will be set to false
isOver18
>>> false
isOver18 >>> false
```

In the above example we check if `age` is greater than 18, but there are many different types of comparisons available:

* Is equal to `10 === 10`
* Is not equal to `10 !== 10`
* Is greater than `10 > 10`
* Is less than `10 < 10`
* Is greater or equal to `10 >= 10`
* Is less or equal to `10 <= 10`
- Is equal to `10 === 10`
- Is not equal to `10 !== 10`
- Is greater than `10 > 10`
- Is less than `10 < 10`
- Is greater or equal to `10 >= 10`
- Is less or equal to `10 <= 10`

As well as comparing numbers, we can also compare strings:

```javascript
"Nicolas" === "Nicolas"
>>> true
'Nicolas' === 'Nicolas' >>> true
```

```javascript
"Nicolas" === "nicolas"
>>> false // it’s case-sensitive
'Nicolas' === 'nicolas' >>> false // it’s case-sensitive
```

```javascript
"Nicolas" !== "nicolas"
>>> true
'Nicolas' !== 'nicolas' >>> true
```

We are not limited to a single comparison - we can use multiple comparisons chained together with either the the logical AND operator `&&` or the logical OR operator `||` (2 pipe characters).

For a chained comparison to return true, `&&` requires that *all* combined expressions are also `true`. For example
For a chained comparison to return true, `&&` requires that _all_ combined expressions are also `true`. For example

```javascript
let age = 10
let isTeenager = age > 12 && age < 20 //false, as age is under 20 but not over 12
>>> false
let isTeenager =
age > 12 &&
age <
20 >>> //false, as age is under 20 but not over 12
false
```

```javascript
age = 14
isTeenager = age > 12 && age < 20 //true, as age is under 20 and over 12
>>> true
isTeenager =
age > 12 &&
age <
20 >>> //true, as age is under 20 and over 12
true
```

```javascript
age = 21
isTeenager = age > 12 && age < 20 //false, as age is over 20 even though greater than 12
>>> false
isTeenager =
age > 12 &&
age <
20 >>> //false, as age is over 20 even though greater than 12
false
```

The OR operator `||` requires that *any of* combined expressions are `true` for the chained expression to return true. For example:
The OR operator `||` requires that _any of_ combined expressions are `true` for the chained expression to return true. For example:

```javascript
age = 10
let withParent = true
isAllowed = age > 17 || withParent //true, withParent is true even though age>17 is false
>>> true
isAllowed =
age > 17 ||
withParent >>> //true, withParent is true even though age>17 is false
true
```

```javascript
age = 10
withParent = false
isAllowed = age > 17 || withParent //false, withParent is false and age>17 is false
>>> false
isAllowed =
age > 17 ||
withParent >>> //false, withParent is false and age>17 is false
false
```

## If Statement
Expand All @@ -103,11 +111,11 @@ Here's a basic example
```javascript
if (true) {
console.log("It's true!")
}
}

if (false) {
console.log("It's not true?")
}
}
```

If we run this code, only the first statement is printed. This is because an `if` statement will only run code in the following block (everything between the curly braces immediately after the `if`) when the expression in between the brackets evaluates to `true`.
Expand All @@ -118,15 +126,15 @@ For example, we can provide a boolean variable:
age = 20
isAllowed = age > 18
if (isAllowed) {
console.log("You can come in!")
console.log('You can come in!')
}
```

But, we can also shorten this and simply provide the expression (`age > 18`) instead:

```javascript
if (age > 18) {
console.log("You can come in!")
console.log('You can come in!')
}
```

Expand All @@ -135,14 +143,14 @@ We can also use the logical AND `&&` and logical OR `||` operators to chain expr
```javascript
//Only allowed in if age greater than 18 AND less than 65
if (age > 18 && age < 65) {
console.log("You can come in!")
console.log('You can come in!')
}
```

```javascript
//Only allowed in if age greater than 18 OR with a parent
if (age > 18 || withParent) {
console.log("You can come in!")
console.log('You can come in!')
}
```

Expand All @@ -151,24 +159,24 @@ If we want to execute some code when an `if` statement evaluates to false, we ca
```javascript
//Only allowed in if age greater than 18 OR with a parent
if (age > 18) {
console.log("You can come in!")
}
else {
console.log('You can come in!')
} else {
console.log("Come back when you're older!")
}
```

The `else if` statement can be used to execute alternative code as long another if condition is met:

```javascript
if (age < 18) { //If under 18
if (age < 18) {
//If under 18
console.log("Come back when you're older!")
}
else if (age > 65) { //If over 18 and older than 65
console.log("Enjoy your retirement!")
}
else { //If over 18 and younger than 65
console.log("You can come in!")
} else if (age > 65) {
//If over 18 and older than 65
console.log('Enjoy your retirement!')
} else {
//If over 18 and younger than 65
console.log('You can come in!')
}
```

Expand All @@ -178,25 +186,25 @@ If you have a lot of comparisons to do, the switch statement can sometimes be a

```javascript
switch (day) {
case "Monday":
case "Tuesday":
case "Wednesday":
case "Thursday":
case "Friday":
dayType = "Weekday"
break;
case 'Monday':
case 'Tuesday':
case 'Wednesday':
case 'Thursday':
case 'Friday':
dayType = 'Weekday'
break
default:
dayType = "Weekend"
dayType = 'Weekend'
}
```

## Next

Work your way through the tests for this section. You can use the references below and also
the `example.js` file to see more code samples. Remember you can make use of the Node REPL
the `example.js` file to see more code samples. Remember you can make use of the Node REPL
to try out and experiment with code.

## References

* [Boolean Conditional Flow Slides](https://docs.google.com/presentation/d/17YZv-apFaaFM0ICtIwZN2moSpKtS4-Mq-heCy6L7kxo/edit#slide=id.gd46f8ee6d4_0_8)
* [MDN If...Else](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else)
- [Boolean Conditional Flow Slides](https://docs.google.com/presentation/d/17YZv-apFaaFM0ICtIwZN2moSpKtS4-Mq-heCy6L7kxo/edit#slide=id.gd46f8ee6d4_0_8)
- [MDN If...Else](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else)
Loading