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

Stian Rusvik #99

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
18 changes: 9 additions & 9 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
name: Node.js CI
on:
pull_request:
branches: [ main ]
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js 17.x
uses: actions/setup-node@v2
with:
node-version: 17.x
cache: 'npm'
- run: npm ci
- run: npm test
- uses: actions/checkout@v2
- name: Use Node.js 17.x
uses: actions/setup-node@v2
with:
node-version: 17.x
cache: 'npm'
- run: npm ci
- run: npm test
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,31 @@ $ npm ci

## Requirements

Inside the `src/fizzbuzz.js` file, write a program that populates the `answer` array with numbers from 1 to 15, *except*:
Inside the `src/fizzbuzz.js` file, write a program that populates the `answer` array with numbers from 1 to 15, _except_:

- When the number is a multiple of three (e.g. 3, 6, 9, etc.), the number should be replaced with the word `Fizz`

- When the number is a multiple of five (e.g. 5, 10, etc.), the number should be replaced with the word `Buzz`

- When the number is a multiple of both three *and* five (e.g. 15), the number should be replaced with the word `FizzBuzz`
- When the number is a multiple of both three _and_ five (e.g. 15), the number should be replaced with the word `FizzBuzz`

## Testing

- At extremely regular intervals, make predictions about what the code you're writing is actually doing and verify whether you're right or wrong using `console.log`

- A simple test has been created inside
`spec/fizzbuzz.spec.js`. You can look at it, but do not edit this file.
`spec/fizzbuzz.spec.js`. You can look at it, but do not edit this file.

- When you think your solution is correct, run the test by executing the following command in your terminal:

```sh
npm test
```

You'll see a lovely green dot if the test passes successfully:

![](./images/passing-test.png)

If the test fails, you'll see a lot of red! Don't worry, we'll learn how to understand error messages like the one below later in the course:

![](./images/failing-test.png)
![](./images/failing-test.png)
20 changes: 18 additions & 2 deletions spec/fizzbuzz.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
const answer = require('../src/fizzbuzz.js')

it("FizzBuzzes", () => {
expect(answer).toEqual([1,2,'Fizz',4,'Buzz','Fizz',7,8,'Fizz','Buzz',11,'Fizz',13,14,'FizzBuzz'])
it('FizzBuzzes', () => {
expect(answer).toEqual([
1,
2,
'Fizz',
4,
'Buzz',
'Fizz',
7,
8,
'Fizz',
'Buzz',
11,
'Fizz',
13,
14,
'FizzBuzz'
])
})
8 changes: 2 additions & 6 deletions spec/support/jasmine.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.?(m)js"
],
"helpers": [
"helpers/**/*.?(m)js"
],
"spec_files": ["**/*[sS]pec.?(m)js"],
"helpers": ["helpers/**/*.?(m)js"],
"stopSpecOnExpectationFailure": false,
"random": false
}
15 changes: 11 additions & 4 deletions src/fizzbuzz.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
const answer = []

// Write your code below this line




for (let i = 1; i <= 15; i++) {
if (i % 3 === 0 && i % 5 === 0) {
answer.push('FizzBuzz')
} else if (i % 3 === 0) {
answer.push('Fizz')
} else if (i % 5 === 0) {
answer.push('Buzz')
} else {
answer.push(i)
}
}

// Don't touch the code below this line, we'll cover it later
module.exports = answer
Loading