This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addTogether() { | |
// Function to check if a number is actually a number | |
// and return undefined otherwise. | |
var checkNum = function(num) { | |
if (typeof num !== 'number') { | |
return undefined; | |
} else | |
return num; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function checkCashRegister(price, cash, cid) { | |
var change = 0; | |
var difference = cash - price; | |
console.log(difference) | |
// Create object with status & change key | |
var cashreg = { | |
status: "", | |
change: [] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ADD = 'ADD'; | |
const reducer = (state = 0, action) => { | |
switch(action.type) { | |
case ADD: | |
return state + 1; | |
default: | |
return state; | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ADD_NOTE = 'ADD_NOTE'; | |
const notesReducer = (state = 'Initial State', action) => { | |
switch(action.type) { | |
// change code below this line | |
case ADD_NOTE: | |
return action.text | |
// change code above this line | |
default: | |
return state; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const REQUESTING_DATA = 'REQUESTING_DATA' | |
const RECEIVED_DATA = 'RECEIVED_DATA' | |
const requestingData = () => { return {type: REQUESTING_DATA} } | |
const receivedData = (data) => { return {type: RECEIVED_DATA, users: data.users} } | |
const handleAsync = () => { | |
return function(dispatch) { | |
// dispatch request action here | |
dispatch(requestingData()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const INCREMENT = 'INCREMENT'; // define a constant for increment action types | |
const DECREMENT = 'DECREMENT'; // define a constant for decrement action types | |
const counterReducer = (state = 0, action) => { | |
switch(action.type) { | |
case INCREMENT: | |
return state + 1 | |
case DECREMENT: | |
return state - 1 | |
default: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const immutableReducer = (state = [0,1,2,3,4,5], action) => { | |
switch(action.type) { | |
case 'REMOVE_ITEM': | |
// don't mutate state here or the tests will fail | |
return [ | |
...state.slice(0, action.index), | |
...state.slice(action.index + 1, state.length) | |
] | |
default: | |
return state; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const defaultState = { | |
user: 'CamperBot', | |
status: 'offline', | |
friends: '732,982', | |
community: 'freeCodeCamp' | |
}; | |
const immutableReducer = (state = defaultState, action) => { | |
switch(action.type) { | |
case 'ONLINE': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DisplayMessages extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
input: '', | |
messages: [] | |
} | |
this.handleChange = this.handleChange.bind(this); | |
this.handleSubmit = this.handleSubmit.bind(this); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// define ADD, addMessage(), messageReducer(), and store here: | |
const ADD = 'ADD'; | |
const messageReducer = (state = [], action) => { | |
switch(action.type) { | |
case ADD: | |
return [ | |
...state, | |
action.message | |
] |