// sample solution to app.js
import React from 'react';
import ReactDOM from 'react-dom';
class Button extends React.Component {
scream() {
alert('AAAAAAAAHHH!!!!!');
}
render() {
return <button onClick={this.scream}>AAAAAH!</button>;
}
}
ReactDOM.render(
<Button />,
document.getElementById('app')
);
Quotes help make search much faster. Example: "Practice Makes Perfect"
Tuesday, August 14, 2018
Codecademy Sample Solution: Use 'this' in a Component
// sample solution to app.js
import React from 'react';
import ReactDOM from 'react-dom';
class MyName extends React.Component {
// name property goes here:
get name() {
return 'Nate';
}
render() {
return <h1>My name is {this.name}.</h1>;
}
}
ReactDOM.render(<MyName />, document.getElementById('app'));
import React from 'react';
import ReactDOM from 'react-dom';
class MyName extends React.Component {
// name property goes here:
get name() {
return 'Nate';
}
render() {
return <h1>My name is {this.name}.</h1>;
}
}
ReactDOM.render(<MyName />, document.getElementById('app'));
Codecademy Sample Solution: Use a Conditional in a Render Function
// sample solution to app.js
import React from 'react';
import ReactDOM from 'react-dom';
const fiftyFifty = Math.random() < 0.5;
// New component class starts here:
class TonightsPlan extends React.Component{
render() {
let task;
if (fiftyFifty) {
task = 'out'
} else {
task = 'to bed'
}
return <h1>Tonight I'm going {task} WOOO</h1>;
}
}
ReactDOM.render(
<TonightsPlan />,
document.getElementById('app')
);
import React from 'react';
import ReactDOM from 'react-dom';
const fiftyFifty = Math.random() < 0.5;
// New component class starts here:
class TonightsPlan extends React.Component{
render() {
let task;
if (fiftyFifty) {
task = 'out'
} else {
task = 'to bed'
}
return <h1>Tonight I'm going {task} WOOO</h1>;
}
}
ReactDOM.render(
<TonightsPlan />,
document.getElementById('app')
);
Codecademy Sample Solution: Put Logic in a Render Function
// sample solution to app.js
import React from 'react';
import ReactDOM from 'react-dom';
const friends = [
{
title: "Yummmmmmm",
src: "https://s3.amazonaws.com/codecademy-content/courses/React/react_photo-monkeyweirdo.jpg"
},
{
title: "Hey Guys! Wait Up!",
src: "https://s3.amazonaws.com/codecademy-content/courses/React/react_photo-earnestfrog.jpg"
},
{
title: "Yikes",
src: "https://s3.amazonaws.com/codecademy-content/courses/React/react_photo-alpaca.jpg"
}
];
// New component class starts here:
class Friend extends React.Component{
render() {
var friend = friends[0];
return (
<div>
<h1>{friend.title}</h1>
<img src={friend.src} />
</div>
);
}
}
ReactDOM.render(
<Friend />,
document.getElementById('app')
);
import React from 'react';
import ReactDOM from 'react-dom';
const friends = [
{
title: "Yummmmmmm",
src: "https://s3.amazonaws.com/codecademy-content/courses/React/react_photo-monkeyweirdo.jpg"
},
{
title: "Hey Guys! Wait Up!",
src: "https://s3.amazonaws.com/codecademy-content/courses/React/react_photo-earnestfrog.jpg"
},
{
title: "Yikes",
src: "https://s3.amazonaws.com/codecademy-content/courses/React/react_photo-alpaca.jpg"
}
];
// New component class starts here:
class Friend extends React.Component{
render() {
var friend = friends[0];
return (
<div>
<h1>{friend.title}</h1>
<img src={friend.src} />
</div>
);
}
}
ReactDOM.render(
<Friend />,
document.getElementById('app')
);
Codecademy Sample Solution: Use a Variable Attribute in a Component
// sample solution for app.js
import React from 'react';
import ReactDOM from 'react-dom';
const owl = {
title: 'Excellent Owl',
src: 'https://s3.amazonaws.com/codecademy-content/courses/React/react_photo-owl.jpg'
};
class Owl extends React.Component {
render() {
return (
<div>
<h1>{owl.title}</h1>
<img
src={owl.src}
alt={owl.title} />
</div>
);
}
}
ReactDOM.render(
<Owl />,
document.getElementById('app')
);
import React from 'react';
import ReactDOM from 'react-dom';
const owl = {
title: 'Excellent Owl',
src: 'https://s3.amazonaws.com/codecademy-content/courses/React/react_photo-owl.jpg'
};
class Owl extends React.Component {
render() {
return (
<div>
<h1>{owl.title}</h1>
<img
src={owl.src}
alt={owl.title} />
</div>
);
}
}
ReactDOM.render(
<Owl />,
document.getElementById('app')
);
Codecademy Sample Solution: Use Multiline JSX in a Component
//sample solution for app.js
import React from 'react';
import ReactDOM from 'react-dom';
class QuoteMaker extends React.Component {
render() {
return (
<blockquote>
<p>
What is important now is to recover our senses.
</p>
<cite>
<a target="_blank"
href="https://en.wikipedia.org/wiki/Susan_Sontag">
Susan Sontag
</a>
</cite>
</blockquote>
);
}
};
ReactDOM.render(
<QuoteMaker />,
document.getElementById('app')
);
import React from 'react';
import ReactDOM from 'react-dom';
class QuoteMaker extends React.Component {
render() {
return (
<blockquote>
<p>
What is important now is to recover our senses.
</p>
<cite>
<a target="_blank"
href="https://en.wikipedia.org/wiki/Susan_Sontag">
Susan Sontag
</a>
</cite>
</blockquote>
);
}
};
ReactDOM.render(
<QuoteMaker />,
document.getElementById('app')
);
Saturday, February 10, 2018
Codeschool Cliffs of Value Sample Solution: Concatenating a Mystery String
Answer:
"eight" + " " + 5 + " " + "six" + " " + "two" + " " + 3 + " " + 7
"eight" + " " + 5 + " " + "six" + " " + "two" + " " + 3 + " " + 7
Codeschool Cliffs of Value Sample Solution: Special Characters In Strings
Answer:
"Quoth the raven:\n\t\"Nevermore!\""
"Quoth the raven:\n\t\"Nevermore!\""
Codeschool Cliffs of Value Sample Solution: Another Boolean Expression
Write an expression where two values are not equal which results as true
Answer:
1!=2
Codeschool Cliffs of Value Sample Solution: A Boolean Expression
Write an expression that checks whether or not two values are equal and evaluates to false
Answer:
1==2
Answer:
1==2
Codeschool Cliffs of Value Modulus Sample Solution
Find an expression using two values and the modulus operator that results as 4
Answer:
32%7
Answer:
32%7
Subscribe to:
Comments (Atom)
This is an example of scrolling text using Javascript.
Popular Posts
-
#sample solution pyg = 'ay' original = raw_input('Enter a word:') if len(original) > 0 and original.isalpha(): p...
-
A typical compounding problem would be something like: How much is the equivalent Present Value (P) if an investment pays an amount (A...
-
A typical compounding problem would be something like: How much will I get annually (A) starting next year if I invest a present value...
-
// Sample solution // Write a string rotation method. // It should pass all the tests given below. String.prototype.rotate = function(n...
-
A typical compounding problem would be something like: What is the future value (F) of a present value (P) deposited/lent at an intere...
-
A typical compounding problem would be something like: What is the present value (P) of a future value (F) if (P) was deposited/lent a...
-
#sample solution class Triangle(object): #member variables number_of_sides = 3 #methods def __init__(self, angle1, angle2, angle...
-
<style> p { font-family: sans-serif; font-size:18px;} div#welcome p{ font-family: cursive; font-size: 24px; color: white; b...
-
#sample solution class Shape(object): """Makes shapes!""" def __init__(self, number_of_sides): self....
-
//Sample Solution const gameState = {} function preload() { this.load.image('codey', 'https://s3.amazonaws.com/codecademy-...