Skip to content

Instantly share code, notes, and snippets.

import React, { Component } from 'react'
import PostList from './components/PostList'
export default class App extends Component {
render() {
return (
<div>
This text is in App.js
<PostList/>
// Call the render function when the page loads in using the jquery ready function
$(function() {
renderDishList();
})
function createDish() {
// grab the stuff from the form and use that to create a new object
const dish = {
title: $("#title-input").val(),
/**
* A prompt that asks a question and only allows certain answers, case insensitive
*/
class QuestionPrompt {
constructor(question, acceptedAnswers) {
this.question = question;
this.acceptedAnswers = acceptedAnswers;
}
getAcceptedAnswer(potentialAnswer) {
/**
* A prompt that asks a question and only allows certain answers, case insensitive
*/
class AcceptedAnswersPrompt {
constructor(question, acceptedAnswers) {
this.question = question;
this.acceptedAnswers = acceptedAnswers;
}
export default function Note() { // creating a function
const match = useRouteMatch(); // calling a function and saving it in a variable
const { noteId } = useParams();
const note = useSelector(state => state.notes.find(n => n.id === noteId)); // calling a function with a parameter
return ( // returning something from a function
<div className="container mt-3">
{ (!note) ? <Redirect to="/notfound"/> :
<Switch>
<Route path={`${match.path}/edit`}>
let animals = [
{
type: "cat",
name: "Floof",
votes: 0
},
{
type: "dog",
name: "Spot",
votes: 0
function getAnswer(question) {
const answer = prompt(question);
return answer;
}
function start() {
let name = getAnswer("What is your name?")
alert("Hello " + name)
name = getAnswer("What is your name?")
body {
background-color: #fafafa;
font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
margin: 0;
padding: 0;
}
p {
font-family: Arial, Helvetica, sans-serif;
let number = Math.ceil(Math.random() * 10)
alert("The secret number is " + number) // just for testing
let gameOn = true
while (gameOn) {
let guess = prompt("Guess a number between 0 and 10")
if (guess === null || guess === "null" || guess === ""){
alert("Game cancelled. Refresh to start again.")
gameOn = false
} else if (parseInt(guess) === number) {
let numCats = prompt("How many cats do you have?");
numCats = parseInt(numCats); // convert the string (ex: "3") to the number (ex: 3)
if(numCats < 1) {
console.log("You need more cats")
}
else if(numCats > 10) {
console.log("That is tooo many cats")
}
else {