Skip to content

Stian Rusvik #275

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

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
2 changes: 1 addition & 1 deletion .github/workflows/extension-criteria-tests.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Extension Criteria
on:
pull_request:
branches: [ main ]
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
Expand Down
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
16 changes: 8 additions & 8 deletions spec/extensions/extension-1.spec.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
const { a, b, c, d } = require('../../src/extensions/example.js')

describe('Example [Extensions]', () => {
it( "Check null", () => {
expect(a).toBe("null");
it('Check null', () => {
expect(a).toBe('null')
})

it( "Check undefined", () => {
expect(b).toBe("undefined");
it('Check undefined', () => {
expect(b).toBe('undefined')
})

it( "Check true", () => {
expect(c).toBe("boolean");
it('Check true', () => {
expect(c).toBe('boolean')
})

it( "Check false", () => {
expect(d).toBe("boolean");
it('Check false', () => {
expect(d).toBe('boolean')
})
})
38 changes: 23 additions & 15 deletions spec/extensions/more-data-types.spec.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
const { a, b, c, d, e, f, g } = require('../../src/extensions/more-data-types.js')
const {
a,
b,
c,
d,
e,
f,
g
} = require('../../src/extensions/more-data-types.js')

describe('Example [Extensions]', () => {
it( "Check null", () => {
expect(a).toBe(null);
it('Check null', () => {
expect(a).toBe(null)
})
it( "Check true", () => {
expect(b).toBe(true);
it('Check true', () => {
expect(b).toBe(true)
})
it( "Check false", () => {
expect(c).toBe(false);
it('Check false', () => {
expect(c).toBe(false)
})
it( "Check undefined", () => {
expect(d).toBe(undefined);
it('Check undefined', () => {
expect(d).toBe(undefined)
})
it( "Check boolean", () => {
expect(e).toBe("boolean");
it('Check boolean', () => {
expect(e).toBe('boolean')
})
it( "Check boolean", () => {
expect(f).toBe("boolean");
it('Check boolean', () => {
expect(f).toBe('boolean')
})
it( "Check undefined", () => {
expect(g).toBe("undefined");
it('Check undefined', () => {
expect(g).toBe('undefined')
})
})
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
}
}
83 changes: 38 additions & 45 deletions src/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Data Types

From text and numbers to lists, people and actions, everything in JavaScript can be represented using data types. Here are the most important ones.

**Primitive types**: These are units that cannot be broken down any further
Expand All @@ -17,30 +18,30 @@ From text and numbers to lists, people and actions, everything in JavaScript can
const isCodingFun = true
```

There’s really not much we can do with a boolean by itself, yet, as we will see later on when we cover conditionals, they are crucial to programming. We usually get true or false as a result of asking our program a question.
There’s really not much we can do with a boolean by itself, yet, as we will see later on when we cover conditionals, they are crucial to programming. We usually get true or false as a result of asking our program a question.

> 👨‍💻 Run these examples in your REPL as you read along! 👨‍💻

```javascript
5 > 3 //Is 5 greater than 3?
>>> true
5 >
3 >>> //Is 5 greater than 3?
true
```

```javascript
5 > 10 //Is 5 greater than 10?
>>> false
5 >
10 >>> //Is 5 greater than 10?
false
```

Booleans can be flipped by adding an exclamation mark right before it:

```javascript
!true
>>> false
!true >>> false
```

```javascript
!false
>>> true
!false >>> true
```

## Numbers
Expand All @@ -54,38 +55,37 @@ As you might expect, anything that you can usually do with numbers you can do in
> 👨‍💻 Run these examples in your REPL as you read along! 👨‍💻

```javascript
10 + 10 //addition
>>> 20
```
;(10 + 10) >>> //addition
20
```

```javascript
10 - 10 //subtraction
>>> 0
```
;(10 - 10) >>> //subtraction
0
```

```javascript
10 * 10 //multiplication
>>> 100
```
;(10 * 10) >>> //multiplication
100
```

```javascript
10 / 10 //division
>>> 1
```
;(10 / 10) >>> //division
1
```

```javascript
24 % 5 // remainder of 24 / 5
>>> 4
24 % 5 >>> // remainder of 24 / 5
4
```

The above examples all use literal values (i.e. a specific number), but we can also perform these operations with variables and store any result in a variable too:

```javascript
const price = 10
const quantity = 2
const cost = price * quantity
console.log(price)
>>> 10
const cost = price * quantity
console.log(price) >>> 10
```

## Strings
Expand All @@ -101,34 +101,29 @@ Strings are simply how we represent text within our programs, from a single char
In JavaScript, we can create a string by wrapping our characters in single , double quotes or backticks:

```javascript
"hey there!"
'hey there!'
`hey there!`
'hey there!'`hey there!`
```

We can add strings together by using the plus `+` operator. This is called **concatenation**.

Run the below code exmaples in your REPL:

```javascript
'Hello' + 'there!'
>> 'Hellothere!'
;('Hello' + 'there!') >> 'Hellothere!'
```

We can also concatenate string variables:

```javascript
const teacher = 'Nicolas'
'Hello ' + teacher + '!'
>>> 'Hello Nicolas!'
;('Hello ' + teacher + '!') >>> 'Hello Nicolas!'
```

Adding variables to a string is called interpolation, and you’ll be doing this a lot! We can also use strings wrapped in back quotes (or backticks) to achieve the same result. This code is equivalent to the above example:

```javascript
const teacherLiteral = 'Nicolas'
`Hello ${teacherLiteral} !`
>>> 'Hello Nicolas!'
const teacherLiteral = 'Nicolas'`Hello ${teacherLiteral} !` >>> 'Hello Nicolas!'
```

This is called a **template literal**.
Expand All @@ -137,32 +132,30 @@ Strings also have a TON of useful helper methods and properties. Here’s a coup

```javascript
const name = 'Nicolas'
name.length
>>> 7
name.length >>> 7
```

```javascript
const nameUpper = 'Nicolas'
nameUpper.toUpperCase()
>>> 'NICOLAS'
nameUpper.toUpperCase() >>> 'NICOLAS'
```

You can also extract a specific character from a string by using the square brackets syntax `string[index]`:

```javascript
const hello = 'Hello'
hello[1] //the index is 0 based! This will return the 2nd character
>>> 'e'
hello[1] >>> //the index is 0 based! This will return the 2nd character
'e'
```

## 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 Variables Slides](https://docs.google.com/presentation/d/17blHGDVfjN_EerQtw0ybFDtJEhjj9wAU9qHoI1DAnYw/edit?usp=sharing)
* [Boolean Strings Slides](https://docs.google.com/presentation/d/1w_cS-TIrEfROoA-OPsC_AxAkdu-1BNkdqkEq-qroNsE/edit?usp=sharing)
* [MDN Data Types](https://developer.mozilla.org/en-US/docs/Glossary/Primitive)
- [Boolean Variables Slides](https://docs.google.com/presentation/d/17blHGDVfjN_EerQtw0ybFDtJEhjj9wAU9qHoI1DAnYw/edit?usp=sharing)
- [Boolean Strings Slides](https://docs.google.com/presentation/d/1w_cS-TIrEfROoA-OPsC_AxAkdu-1BNkdqkEq-qroNsE/edit?usp=sharing)
- [MDN Data Types](https://developer.mozilla.org/en-US/docs/Glossary/Primitive)
14 changes: 7 additions & 7 deletions src/extensions/more-data-types.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
// TODO: Replace the empty string in the lines below using Javascript with the correct data types

// 1. Set this variable to be null
const nullVariable = ''
const nullVariable = null

// 2. Set this variable to be true
const trueVariable = ''
const trueVariable = true

// 2. Set this variable to be the opposite of the trueVariable (ie. false);
const falseVariable = ''
const falseVariable = false

// 3. Set this variable to be undefined
const undefinedVariable = ''
const undefinedVariable = undefined

// 4. get the typeof each of the above variables
// hint you can use typeof variable to return a string of the variable type
const typeOfTrueVariable = ''
const typeOfFalseVariable = ''
const typeOfUndefinedVariable = ''
const typeOfTrueVariable = typeof trueVariable
const typeOfFalseVariable = typeof falseVariable
const typeOfUndefinedVariable = typeof undefinedVariable

// do not edit the exported object.
module.exports = {
Expand Down
12 changes: 6 additions & 6 deletions src/numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ const numThree = 32
// NOT myAnswer = 336

// 1. Set this variable to numOne added to numTwo
const numOnePlusNumTwo = NaN
const numOnePlusNumTwo = numOne + numTwo

// 2. Set this variable to numThree multiplied by numTwo
const numThreeTimesNumTwo = NaN
const numThreeTimesNumTwo = numThree * numTwo

// 3. Set this variable to numThree divided by numOne
const numThreeDividedByNumOne = NaN
const numThreeDividedByNumOne = numThree / numOne

// 4. Set this variable to numThree minus numOne
const numThreeMinusNumOne = NaN
const numThreeMinusNumOne = numThree - numOne

// 5. Set this variable to the sum of numOne, numTwo and numThree
const sum = NaN
const sum = numOne + numTwo + numThree

// 6. Set this variable to the sum of (numOne, numTwo, numThree) divided by numOne
const numBytes = NaN
const numBytes = (numOne + numTwo + numThree) / numOne

// do not edit the exported object.
module.exports = {
Expand Down
8 changes: 4 additions & 4 deletions src/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ const secondName = 'Smith'
// NOT twoJanes = "JaneJane"

// 1. Set this variable to firstName and secondName concatenated
const fullName = null
const fullName = firstName + ' ' + secondName

// 2. Set this variable to the 10th character of the alphabet variable
const tenthCharacterOfAlphabet = null
const tenthCharacterOfAlphabet = alphabet.charAt(9)

// 3. Set this variable by calling a method on the alphabet variable to transform it to lower case
const lowerCaseAlphabet = null
const lowerCaseAlphabet = alphabet.toLocaleLowerCase()

// 4. Set this variable by using a property on the alphabet variable to get it's length
const numberOfLettersInAlphabet = null
const numberOfLettersInAlphabet = alphabet.length

// do not edit the exported object.
module.exports = {
Expand Down
Loading