Skip to content

Instantly share code, notes, and snippets.

const messages = [
{
id: 0,
from: "Abigail",
text: "Are you here yet?",
unread: true
},
{
id: 1,
from: "Jose",
function App() {
const [channels, setchannels] = useState(INITIAL_CHANNELS)
const handleUpdateChannel = (updatedChannelData) => {
// set the state to the new updated data
}
return (
<div>
<Sidebar channelList={ channels }/>
addLike() {
//this.state.transactionList = fdjskflds // DO NOT CHANGE STATE DIRECTLY
// let something = this.state.transactionList.push({ fdjskfldsfjklds }) // DO NOT CHANGE STATE DIRECTLY
// this.setState({ transactionList: something })
this.setState(state => ({ numLikes: state.numLikes + 1 }) )
// adding
this.setState( state => ({ transactionList: [ ...state.transactionList, "fdsfdsfsd"] }) )
this.setState( state => ({ transactionList: state.transactionList.concat(["fdsfdsfsd"]) }) )
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="week2.js"></script>
function cookInOven(food, temperature) { // food = "chicken", temperature = 425
return food + " cooked at " + temperature
}
function cookDinner(ingredients) {
var cookedFoodArray = [];
for(let i = 0; i < ingredients.length; i++) {
var cookedFood = cookInOven(ingredients[i], 400)
cookedFoodArray.push(cookedFood)
}
// Working with one email
const emailFromNatalie = {
author: "Natalie",
to: "Calvin",
message: "Heyyyy",
read: false
}
alert(emailFromNatalie.message)
// Prompt for a number of cats and parse it into a number
var numCats = prompt("How many cats do you have?")
numCats = parseInt(numCats)
// Loop as long as they don't give us a real number
while( !(numCats >= 0) ) {
numCats = prompt("No really, how many cats?");
numCats = parseInt(numCats)
}
class AcceptedAnswerPrompt {
constructor(acceptedAnswers) {
this.acceptedAnswers = acceptedAnswers;
}
checkIfAccepted(answer) {
// return true if it is in the list of accepted answer
for(const acceptedAnswer of this.acceptedAnswers) {
if(acceptedAnswer === answer) {
return true;
// Cooks in pressure cooker
function cookInPressureCooker(howLong, food) { // var howLong = 20; var food = "chicken"
return food + " cooked for " + 20 + " minutes";
}
function makeDinner() {
var chicken = "chicken";
var soup = "soup";
chicken = cookInPressureCooker(20, "chicken");
class AcceptedAnswerPrompt {
constructor(acceptedAnswers) {
this.acceptedAnswers = acceptedAnswers;
}
checkIfAccepted(answer) {
// return true if it is in the list of accepted answer
for(const acceptedAnswer of this.acceptedAnswers) {
if(acceptedAnswer === answer) {