fix: consolidated comments for use with translation dictionary (#39578)

This commit is contained in:
Randell Dawson
2020-09-15 09:53:25 -07:00
committed by GitHub
parent 104f359902
commit a2f4c8d0e1
87 changed files with 289 additions and 294 deletions

View File

@ -10,7 +10,7 @@ forumTopicId: 18347
When we start using jQuery, we will modify HTML elements without needing to actually change them in HTML. When we start using jQuery, we will modify HTML elements without needing to actually change them in HTML.
Let's make sure that everyone knows they shouldn't actually modify any of this code directly. Let's make sure that everyone knows they shouldn't actually modify any of this code directly.
Remember that you can start a comment with <code>&#60;!--</code> and end a comment with <code>--&#62;</code> Remember that you can start a comment with <code>&#60;!--</code> and end a comment with <code>--&#62;</code>
Add a comment at the top of your HTML that says <code>Only change code above this line.</code> Add a comment at the top of your HTML that says <code>Code below this line should not be changed</code>
</section> </section>
## Instructions ## Instructions
@ -25,7 +25,7 @@ Add a comment at the top of your HTML that says <code>Only change code above thi
tests: tests:
- text: You should start a comment with <code>&#60;!--</code> at the top of your HTML. - text: You should start a comment with <code>&#60;!--</code> at the top of your HTML.
testString: assert(code.match(/^\s*<!--/)); testString: assert(code.match(/^\s*<!--/));
- text: Your comment should have the text <code>Only change code above this line</code>. - text: Your comment should have the text <code>Code below this line should not be changed</code>.
testString: assert(code.match(/<!--(?!(>|->|.*-->.*this line))\s*.*this line.*\s*-->/gi)); testString: assert(code.match(/<!--(?!(>|->|.*-->.*this line))\s*.*this line.*\s*-->/gi));
- text: You should close your comment with <code>--&#62;</code>. - text: You should close your comment with <code>--&#62;</code>.
testString: assert(code.match(/-->.*\n+.+/g)); testString: assert(code.match(/-->.*\n+.+/g));
@ -75,7 +75,7 @@ tests:
<section id='solution'> <section id='solution'>
```html ```html
<!-- Only change code above this line. --> <!-- Code below this line should not be changed -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row"> <div class="row">

View File

@ -55,7 +55,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>

View File

@ -53,7 +53,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>
@ -98,7 +98,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>
<div class="row"> <div class="row">

View File

@ -52,7 +52,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>
@ -97,7 +97,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>

View File

@ -53,7 +53,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>
@ -94,7 +94,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>

View File

@ -49,7 +49,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>
@ -92,7 +92,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>

View File

@ -43,7 +43,7 @@ tests:
<div id='html-seed'> <div id='html-seed'>
```html ```html
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>
@ -82,7 +82,7 @@ tests:
$(document).ready(function() { $(document).ready(function() {
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>

View File

@ -45,7 +45,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>
@ -88,7 +88,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>

View File

@ -51,7 +51,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>
@ -95,7 +95,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>

View File

@ -59,7 +59,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>
@ -107,7 +107,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>

View File

@ -49,7 +49,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>
@ -91,7 +91,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>

View File

@ -52,7 +52,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>
@ -95,7 +95,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>

View File

@ -58,7 +58,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>
@ -108,7 +108,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>

View File

@ -49,7 +49,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>
@ -90,7 +90,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>

View File

@ -52,7 +52,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>
@ -99,7 +99,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>

View File

@ -55,7 +55,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<body> <body>
<div class="container-fluid"> <div class="container-fluid">
@ -103,7 +103,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<body> <body>
<div class="container-fluid"> <div class="container-fluid">

View File

@ -57,7 +57,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>
@ -100,7 +100,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>

View File

@ -50,7 +50,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>
@ -94,7 +94,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>

View File

@ -54,7 +54,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>
@ -105,7 +105,7 @@ tests:
}); });
</script> </script>
<!-- Only change code above this line. --> <!-- Only change code above this line -->
<div class="container-fluid"> <div class="container-fluid">
<h3 class="text-primary text-center">jQuery Playground</h3> <h3 class="text-primary text-center">jQuery Playground</h3>

View File

@ -72,7 +72,7 @@ class Presentational extends React.Component {
}; };
const connect = ReactRedux.connect; const connect = ReactRedux.connect;
// change code below this line // Change code below this line
``` ```
@ -139,7 +139,7 @@ class Presentational extends React.Component {
}; };
const connect = ReactRedux.connect; const connect = ReactRedux.connect;
// change code below this line // Change code below this line
const ConnectedComponent = connect(mapStateToProps, mapDispatchToProps)(Presentational); const ConnectedComponent = connect(mapStateToProps, mapDispatchToProps)(Presentational);

View File

@ -129,7 +129,7 @@ const mapDispatchToProps = (dispatch) => {
const Provider = ReactRedux.Provider; const Provider = ReactRedux.Provider;
const connect = ReactRedux.connect; const connect = ReactRedux.connect;
// define the Container component here: // Define the Container component here:
class AppWrapper extends React.Component { class AppWrapper extends React.Component {
@ -137,7 +137,7 @@ class AppWrapper extends React.Component {
super(props); super(props);
} }
render() { render() {
// complete the return statement: // Complete the return statement:
return (null); return (null);
} }
}; };
@ -248,7 +248,6 @@ const mapDispatchToProps = (dispatch) => {
const Provider = ReactRedux.Provider; const Provider = ReactRedux.Provider;
const connect = ReactRedux.connect; const connect = ReactRedux.connect;
// define the Container component here:
const Container = connect(mapStateToProps, mapDispatchToProps)(Presentational); const Container = connect(mapStateToProps, mapDispatchToProps)(Presentational);
class AppWrapper extends React.Component { class AppWrapper extends React.Component {
@ -256,7 +255,6 @@ class AppWrapper extends React.Component {
super(props); super(props);
} }
render() { render() {
// complete the return statement:
return ( return (
<Provider store={store}> <Provider store={store}>
<Container/> <Container/>

View File

@ -45,7 +45,7 @@ tests:
<div id='jsx-seed'> <div id='jsx-seed'>
```jsx ```jsx
// define ADD, addMessage(), messageReducer(), and store here: // Define ADD, addMessage(), messageReducer(), and store here:
``` ```

View File

@ -41,9 +41,9 @@ tests:
```jsx ```jsx
class DisplayMessages extends React.Component { class DisplayMessages extends React.Component {
// change code below this line // Change code below this line
// change code above this line // Change code above this line
render() { render() {
return <div /> return <div />
} }

View File

@ -56,15 +56,15 @@ class DisplayMessages extends React.Component {
messages: [] messages: []
} }
} }
// add handleChange() and submitMessage() methods here // Add handleChange() and submitMessage() methods here
render() { render() {
return ( return (
<div> <div>
<h2>Type in a new Message:</h2> <h2>Type in a new Message:</h2>
{ /* render an input, button, and ul here */ } { /* Render an input, button, and ul below this line */ }
{ /* change code above this line */ } { /* Change code above this line */ }
</div> </div>
); );
} }

View File

@ -57,7 +57,7 @@ const addMessage = (message) => {
} }
}; };
// change code below this line // Change code below this line
``` ```
@ -79,7 +79,7 @@ const addMessage = (message) => {
} }
}; };
// change code below this line // Change code below this line
const mapDispatchToProps = (dispatch) => { const mapDispatchToProps = (dispatch) => {
return { return {

View File

@ -44,7 +44,7 @@ tests:
```jsx ```jsx
const state = []; const state = [];
// change code below this line // Change code below this line
``` ```
@ -61,7 +61,7 @@ const state = [];
```js ```js
const state = []; const state = [];
// change code below this line // Change code below this line
const mapStateToProps = (state) => { const mapStateToProps = (state) => {
return { return {

View File

@ -37,28 +37,28 @@ tests:
<div id='jsx-seed'> <div id='jsx-seed'>
```jsx ```jsx
// import React from 'react' /*
// import ReactDOM from 'react-dom' import React from 'react'
// import { Provider, connect } from 'react-redux' import ReactDOM from 'react-dom'
// import { createStore, combineReducers, applyMiddleware } from 'redux' import { Provider, connect } from 'react-redux'
// import thunk from 'redux-thunk' import { createStore, combineReducers, applyMiddleware } from 'redux'
import thunk from 'redux-thunk'
// import rootReducer from './redux/reducers' import rootReducer from './redux/reducers'
// import App from './components/App' import App from './components/App'
// const store = createStore( const store = createStore(
// rootReducer, rootReducer,
// applyMiddleware(thunk) applyMiddleware(thunk)
// ); );
// ReactDOM.render( ReactDOM.render(
// <Provider store={store}> <Provider store={store}>
// <App/> <App/>
// </Provider>, </Provider>,
// document.getElementById('root') document.getElementById('root')
// ); );
*/
// change code below this line
``` ```

View File

@ -49,7 +49,7 @@ tests:
<div id='jsx-seed'> <div id='jsx-seed'>
```jsx ```jsx
// Redux Code: // Redux:
const ADD = 'ADD'; const ADD = 'ADD';
const addMessage = (message) => { const addMessage = (message) => {
@ -75,7 +75,7 @@ const messageReducer = (state = [], action) => {
const store = Redux.createStore(messageReducer); const store = Redux.createStore(messageReducer);
// React Code: // React:
class DisplayMessages extends React.Component { class DisplayMessages extends React.Component {
constructor(props) { constructor(props) {
@ -125,9 +125,9 @@ class DisplayMessages extends React.Component {
const Provider = ReactRedux.Provider; const Provider = ReactRedux.Provider;
class AppWrapper extends React.Component { class AppWrapper extends React.Component {
// render the Provider here // Render the Provider below this line
// change code above this line // Change code above this line
}; };
``` ```
@ -150,7 +150,7 @@ ReactDOM.render(<AppWrapper />, document.getElementById('root'))
```js ```js
// Redux Code: // Redux:
const ADD = 'ADD'; const ADD = 'ADD';
const addMessage = (message) => { const addMessage = (message) => {
@ -174,7 +174,7 @@ const messageReducer = (state = [], action) => {
const store = Redux.createStore(messageReducer); const store = Redux.createStore(messageReducer);
// React Code: // React:
class DisplayMessages extends React.Component { class DisplayMessages extends React.Component {
constructor(props) { constructor(props) {
@ -224,7 +224,7 @@ class DisplayMessages extends React.Component {
const Provider = ReactRedux.Provider; const Provider = ReactRedux.Provider;
class AppWrapper extends React.Component { class AppWrapper extends React.Component {
// change code below this line // Change code below this line
render() { render() {
return ( return (
<Provider store = {store}> <Provider store = {store}>
@ -232,7 +232,7 @@ class AppWrapper extends React.Component {
</Provider> </Provider>
); );
} }
// change code above this line // Change code above this line
}; };
``` ```

View File

@ -51,9 +51,9 @@ class ReturnTempPassword extends React.Component {
render() { render() {
return ( return (
<div> <div>
{ /* change code below this line */ } { /* Change code below this line */ }
<p>Your temporary password is: <strong></strong></p> <p>Your temporary password is: <strong></strong></p>
{ /* change code above this line */ } { /* Change code above this line */ }
</div> </div>
); );
} }
@ -70,9 +70,9 @@ class ResetPassword extends React.Component {
<h2>Reset Password</h2> <h2>Reset Password</h2>
<h3>We've generated a new temporary password for you.</h3> <h3>We've generated a new temporary password for you.</h3>
<h3>Please reset this password from your account settings ASAP.</h3> <h3>Please reset this password from your account settings ASAP.</h3>
{ /* change code below this line */ } { /* Change code below this line */ }
{ /* change code above this line */ } { /* Change code above this line */ }
</div> </div>
); );
} }
@ -123,9 +123,9 @@ class ResetPassword extends React.Component {
<h2>Reset Password</h2> <h2>Reset Password</h2>
<h3>We've generated a new temporary password for you.</h3> <h3>We've generated a new temporary password for you.</h3>
<h3>Please reset this password from your account settings ASAP.</h3> <h3>Please reset this password from your account settings ASAP.</h3>
{ /* change code below this line */ } { /* Change code below this line */ }
<ReturnTempPassword tempPassword="serrPbqrPnzc" /> <ReturnTempPassword tempPassword="serrPbqrPnzc" />
{ /* change code above this line */ } { /* Change code above this line */ }
</div> </div>
); );
} }

View File

@ -51,14 +51,14 @@ class MyComponent extends React.Component {
this.handleEnter = this.handleEnter.bind(this); this.handleEnter = this.handleEnter.bind(this);
this.handleKeyPress = this.handleKeyPress.bind(this); this.handleKeyPress = this.handleKeyPress.bind(this);
} }
// change code below this line // Change code below this line
componentDidMount() { componentDidMount() {
} }
componentWillUnmount() { componentWillUnmount() {
} }
// change code above this line // Change code above this line
handleEnter() { handleEnter() {
this.setState((state) => ({ this.setState((state) => ({
message: state.message + 'You pressed the enter key! ' message: state.message + 'You pressed the enter key! '
@ -107,14 +107,14 @@ class MyComponent extends React.Component {
this.handleKeyPress = this.handleKeyPress.bind(this); this.handleKeyPress = this.handleKeyPress.bind(this);
this.handleEnter = this.handleEnter.bind(this); } this.handleEnter = this.handleEnter.bind(this); }
componentDidMount() { componentDidMount() {
// change code below this line // Change code below this line
document.addEventListener('keydown', this.handleKeyPress); document.addEventListener('keydown', this.handleKeyPress);
// change code above this line // Change code above this line
} }
componentWillUnmount() { componentWillUnmount() {
// change code below this line // Change code below this line
document.removeEventListener('keydown', this.handleKeyPress); document.removeEventListener('keydown', this.handleKeyPress);
// change code above this line // Change code above this line
} }
handleEnter() { handleEnter() {
this.setState((state) => ({ this.setState((state) => ({

View File

@ -14,7 +14,7 @@ All property value length units (like <code>height</code>, <code>width</code>, a
## Instructions ## Instructions
<section id='instructions'> <section id='instructions'>
If you have a large set of styles, you can assign a style <code>object</code> to a constant to keep your code organized. Uncomment the <code>styles</code> constant and declare an <code>object</code> with three style properties and their values. Give the <code>div</code> a color of <code>"purple"</code>, a font-size of <code>40</code>, and a border of <code>"2px solid purple"</code>. Then set the <code>style</code> attribute equal to the <code>styles</code> constant. If you have a large set of styles, you can assign a style <code>object</code> to a constant to keep your code organized. Initialize a <code>styles</code> constant and assign an <code>object</code> with three style properties and their values to it. Give the <code>div</code> a color of <code>"purple"</code>, a font-size of <code>40</code>, and a border of <code>"2px solid purple"</code>. Then set the <code>style</code> attribute equal to the <code>styles</code> constant.
</section> </section>
## Tests ## Tests
@ -46,15 +46,15 @@ tests:
```jsx ```jsx
// const styles =
// change code above this line // Change code above this line
class Colorful extends React.Component { class Colorful extends React.Component {
render() { render() {
// change code below this line // Change code below this line
return ( return (
<div style={{color: "yellow", fontSize: 24}}>Style Me!</div> <div style={{color: "yellow", fontSize: 24}}>Style Me!</div>
); );
// change code above this line // Change code above this line
} }
}; };
@ -84,14 +84,14 @@ const styles = {
fontSize: 40, fontSize: 40,
border: "2px solid purple" border: "2px solid purple"
}; };
// change code above this line // Change code above this line
class Colorful extends React.Component { class Colorful extends React.Component {
render() { render() {
// change code below this line // Change code below this line
return ( return (
<div style={styles}>Style Me!</div> <div style={styles}>Style Me!</div>
// change code above this line
); );
// Change code above this line
} }
}; };

View File

@ -48,9 +48,9 @@ class MyComponent extends React.Component {
this.state = { this.state = {
text: "Hello" text: "Hello"
}; };
// change code below this line // Change code below this line
// change code above this line // Change code above this line
} }
handleClick() { handleClick() {
this.setState({ this.setState({
@ -60,9 +60,9 @@ class MyComponent extends React.Component {
render() { render() {
return ( return (
<div> <div>
{ /* change code below this line */ } { /* Change code below this line */ }
<button>Click Me</button> <button>Click Me</button>
{ /* change code above this line */ } { /* Change code above this line */ }
<h1>{this.state.text}</h1> <h1>{this.state.text}</h1>
</div> </div>
); );

View File

@ -59,9 +59,9 @@ class GateKeeper extends React.Component {
let inputStyle = { let inputStyle = {
border: '1px solid black' border: '1px solid black'
}; };
// change code below this line // Change code below this line
// change code above this line // Change code above this line
return ( return (
<div> <div>
<h3>Don't Type Too Much:</h3> <h3>Don't Type Too Much:</h3>

View File

@ -49,9 +49,9 @@ class Fruits extends React.Component {
return ( return (
<div> <div>
<h2>Fruits:</h2> <h2>Fruits:</h2>
{ /* change code below this line */ } { /* Change code below this line */ }
{ /* change code above this line */ } { /* Change code above this line */ }
</div> </div>
); );
} }
@ -65,9 +65,9 @@ class TypesOfFood extends React.Component {
return ( return (
<div> <div>
<h1>Types of Food:</h1> <h1>Types of Food:</h1>
{ /* change code below this line */ } { /* Change code below this line */ }
{ /* change code above this line */ } { /* Change code above this line */ }
<Vegetables /> <Vegetables />
</div> </div>
); );
@ -153,10 +153,10 @@ class Fruits extends React.Component {
return ( return (
<div> <div>
<h2>Fruits:</h2> <h2>Fruits:</h2>
{ /* change code below this line */ } { /* Change code below this line */ }
<NonCitrus /> <NonCitrus />
<Citrus /> <Citrus />
{ /* change code above this line */ } { /* Change code above this line */ }
</div> </div>
) )
} }
@ -170,9 +170,9 @@ class TypesOfFood extends React.Component {
return ( return (
<div> <div>
<h1>Types of Food:</h1> <h1>Types of Food:</h1>
{ /* change code below this line */ } { /* Change code below this line */ }
<Fruits /> <Fruits />
{ /* change code above this line */ } { /* Change code above this line */ }
<Vegetables /> <Vegetables />
</div> </div>
); );

View File

@ -66,7 +66,7 @@ tests:
<div id='jsx-seed'> <div id='jsx-seed'>
```jsx ```jsx
// write your code here
``` ```

View File

@ -68,10 +68,10 @@ class ParentComponent extends React.Component {
return ( return (
<div> <div>
<h1>I am the parent</h1> <h1>I am the parent</h1>
{ /* change code below this line */ } { /* Change code below this line */ }
{ /* change code above this line */ } { /* Change code above this line */ }
</div> </div>
); );
} }
@ -113,9 +113,9 @@ class ParentComponent extends React.Component {
return ( return (
<div> <div>
<h1>I am the parent</h1> <h1>I am the parent</h1>
{ /* change code below this line */ } { /* Change code below this line */ }
<ChildComponent /> <ChildComponent />
{ /* change code above this line */ } { /* Change code above this line */ }
</div> </div>
); );
} }

View File

@ -124,22 +124,22 @@ class MyForm extends React.Component {
}); });
} }
handleSubmit(event) { handleSubmit(event) {
// change code below this line // Change code below this line
// change code above this line // Change code above this line
} }
render() { render() {
return ( return (
<div> <div>
<form onSubmit={this.handleSubmit}> <form onSubmit={this.handleSubmit}>
{/* change code below this line */} {/* Change code below this line */}
{/* change code above this line */} {/* Change code above this line */}
<button type='submit'>Submit!</button> <button type='submit'>Submit!</button>
</form> </form>
{/* change code below this line */} {/* Change code below this line */}
{/* change code above this line */} {/* Change code above this line */}
</div> </div>
); );
} }

View File

@ -48,19 +48,19 @@ class ControlledInput extends React.Component {
this.state = { this.state = {
input: '' input: ''
}; };
// change code below this line // Change code below this line
// change code above this line // Change code above this line
} }
// change code below this line // Change code below this line
// change code above this line // Change code above this line
render() { render() {
return ( return (
<div> <div>
{ /* change code below this line */} { /* Change code below this line */}
{ /* change code above this line */} { /* Change code above this line */}
<h4>Controlled Input:</h4> <h4>Controlled Input:</h4>
<p>{this.state.input}</p> <p>{this.state.input}</p>
</div> </div>

View File

@ -61,11 +61,11 @@ class MyComponent extends React.Component {
super(props); super(props);
} }
render() { render() {
// change code below this line // Change code below this line
// change code above this line // Change code above this line
} }
}; };
``` ```
@ -94,13 +94,13 @@ class MyComponent extends React.Component {
super(props); super(props);
} }
render() { render() {
// change code below this line // Change code below this line
return ( return (
<div> <div>
<h1>Hello React!</h1> <h1>Hello React!</h1>
</div> </div>
); );
// change code above this line // Change code above this line
} }
}; };
``` ```

View File

@ -53,8 +53,9 @@ tests:
class StatefulComponent extends React.Component { class StatefulComponent extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
// initialize state here // Only change code below this line
// Only change code above this line
} }
render() { render() {
return ( return (

View File

@ -53,11 +53,11 @@ tests:
```jsx ```jsx
const MyComponent = function() { const MyComponent = function() {
// change code below this line // Change code below this line
// change code above this line // Change code above this line
} }
``` ```
@ -81,13 +81,13 @@ ReactDOM.render(<MyComponent />, document.getElementById('root'))
```js ```js
const MyComponent = function() { const MyComponent = function() {
// change code below this line // Change code below this line
return ( return (
<div> <div>
Demo Solution Demo Solution
</div> </div>
); );
// change code above this line // Change code above this line
} }
``` ```

View File

@ -56,7 +56,7 @@ const frontEndFrameworks = [
]; ];
function Frameworks() { function Frameworks() {
const renderFrameworks = null; // change code here const renderFrameworks = null; // Change this line
return ( return (
<div> <div>
<h1>Popular Front End JavaScript Frameworks</h1> <h1>Popular Front End JavaScript Frameworks</h1>

View File

@ -44,11 +44,9 @@ tests:
```jsx ```jsx
const JSX = ( const JSX = (
<div> <div>
{/* remove comment and change code below this line
<h2>Welcome to React!</h2> <br > <h2>Welcome to React!</h2> <br >
<p>Be sure to close all tags!</p> <p>Be sure to close all tags!</p>
<hr > <hr >
remove comment and change code above this line */}
</div> </div>
); );
@ -75,11 +73,9 @@ ReactDOM.render(JSX, document.getElementById('root'))
```js ```js
const JSX = ( const JSX = (
<div> <div>
{/* change code below this line */}
<h2>Welcome to React!</h2> <br /> <h2>Welcome to React!</h2> <br />
<p>Be sure to close all tags!</p> <p>Be sure to close all tags!</p>
<hr /> <hr />
{/* change code above this line */}
</div> </div>
); );
``` ```

View File

@ -84,9 +84,9 @@ class OnlyEvens extends React.Component {
} }
shouldComponentUpdate(nextProps, nextState) { shouldComponentUpdate(nextProps, nextState) {
console.log('Should I update?'); console.log('Should I update?');
// change code below this line // Change code below this line
return true; return true;
// change code above this line // Change code above this line
} }
componentDidUpdate() { componentDidUpdate() {
console.log('Component re-rendered.'); console.log('Component re-rendered.');
@ -145,9 +145,9 @@ class OnlyEvens extends React.Component {
} }
shouldComponentUpdate(nextProps, nextState) { shouldComponentUpdate(nextProps, nextState) {
console.log('Should I update?'); console.log('Should I update?');
// change code below this line // Change code below this line
return nextProps.value % 2 === 0; return nextProps.value % 2 === 0;
// change code above this line // Change code above this line
} }
componentDidUpdate() { componentDidUpdate() {
console.log('Component re-rendered.'); console.log('Component re-rendered.');

View File

@ -52,9 +52,9 @@ class ShoppingCart extends React.Component {
super(props); super(props);
} }
render() { render() {
{ /* change code below this line */ } { /* Change code below this line */ }
return <Items /> return <Items />
{ /* change code above this line */ } { /* Change code above this line */ }
} }
}; };
``` ```
@ -91,9 +91,9 @@ class ShoppingCart extends React.Component {
super(props); super(props);
} }
render() { render() {
{ /* change code below this line */ } { /* Change code below this line */ }
return <Items quantity = {10} /> return <Items quantity = {10} />
{ /* change code above this line */ } { /* Change code above this line */ }
} }
}; };
``` ```

View File

@ -59,9 +59,9 @@ class MyApp extends React.Component {
render() { render() {
return ( return (
<div> <div>
{ /* change code below this line */ } { /* Change code below this line */ }
{ /* change code above this line */ } { /* Change code above this line */ }
</div> </div>
); );
} }

View File

@ -66,9 +66,9 @@ tests:
```jsx ```jsx
const List = (props) => { const List = (props) => {
{ /* change code below this line */ } { /* Change code below this line */ }
return <p>{}</p> return <p>{}</p>
{ /* change code above this line */ } { /* Change code above this line */ }
}; };
class ToDo extends React.Component { class ToDo extends React.Component {
@ -80,11 +80,11 @@ class ToDo extends React.Component {
<div> <div>
<h1>To Do Lists</h1> <h1>To Do Lists</h1>
<h2>Today</h2> <h2>Today</h2>
{ /* change code below this line */ } { /* Change code below this line */ }
<List/> <List/>
<h2>Tomorrow</h2> <h2>Tomorrow</h2>
<List/> <List/>
{ /* change code above this line */ } { /* Change code above this line */ }
</div> </div>
); );
} }

View File

@ -63,9 +63,9 @@ tests:
const CurrentDate = (props) => { const CurrentDate = (props) => {
return ( return (
<div> <div>
{ /* change code below this line */ } { /* Change code below this line */ }
<p>The current date is: </p> <p>The current date is: </p>
{ /* change code above this line */ } { /* Change code above this line */ }
</div> </div>
); );
}; };
@ -78,9 +78,9 @@ class Calendar extends React.Component {
return ( return (
<div> <div>
<h3>What date is it?</h3> <h3>What date is it?</h3>
{ /* change code below this line */ } { /* Change code below this line */ }
<CurrentDate /> <CurrentDate />
{ /* change code above this line */ } { /* Change code above this line */ }
</div> </div>
); );
} }
@ -109,9 +109,9 @@ ReactDOM.render(<Calendar />, document.getElementById('root'))
const CurrentDate = (props) => { const CurrentDate = (props) => {
return ( return (
<div> <div>
{ /* change code below this line */ } { /* Change code below this line */ }
<p>The current date is: {props.date}</p> <p>The current date is: {props.date}</p>
{ /* change code above this line */ } { /* Change code above this line */ }
</div> </div>
); );
}; };
@ -124,9 +124,9 @@ class Calendar extends React.Component {
return ( return (
<div> <div>
<h3>What date is it?</h3> <h3>What date is it?</h3>
{ /* change code below this line */ } { /* Change code below this line */ }
<CurrentDate date={Date()} /> <CurrentDate date={Date()} />
{ /* change code above this line */ } { /* Change code above this line */ }
</div> </div>
); );
} }

View File

@ -15,7 +15,7 @@ This pattern illustrates some important paradigms in React. The first is <em>uni
## Instructions ## Instructions
<section id='instructions'> <section id='instructions'>
The <code>MyApp</code> component is stateful and renders a <code>Navbar</code> component as a child. Pass the <code>name</code> property in its <code>state</code> down to the child component, then show the <code>name</code> in the <code>h1</code> tag that's part of the <code>Navbar</code> render method. The <code>MyApp</code> component is stateful and renders a <code>Navbar</code> component as a child. Pass the <code>name</code> property in its <code>state</code> down to the child component, then show the <code>name</code> in the <code>h1</code> tag that's part of the <code>Navbar</code> render method. <code>name</code> should appear after the text <code>Hello, my name is: </code>.
</section> </section>
## Tests ## Tests
@ -50,7 +50,9 @@ class MyApp extends React.Component {
render() { render() {
return ( return (
<div> <div>
<Navbar /* your code here */ /> {/* Change code below this line */}
<Navbar />
{/* Change code above this line */}
</div> </div>
); );
} }
@ -63,7 +65,9 @@ class Navbar extends React.Component {
render() { render() {
return ( return (
<div> <div>
<h1>Hello, my name is: {/* your code here */} </h1> {/* Change code below this line */}
<h1>Hello, my name is: </h1>
{/* Change code above this line */}
</div> </div>
); );
} }

View File

@ -51,15 +51,15 @@ class TypesOfFood extends React.Component {
return ( return (
<div> <div>
<h1>Types of Food:</h1> <h1>Types of Food:</h1>
{/* change code below this line */} {/* Change code below this line */}
{/* change code above this line */} {/* Change code above this line */}
</div> </div>
); );
} }
}; };
// change code below this line // Change code below this line
``` ```
@ -124,16 +124,16 @@ class TypesOfFood extends React.Component {
return ( return (
<div> <div>
<h1>Types of Food:</h1> <h1>Types of Food:</h1>
{/* change code below this line */} {/* Change code below this line */}
<Fruits /> <Fruits />
<Vegetables /> <Vegetables />
{/* change code above this line */} {/* Change code above this line */}
</div> </div>
); );
} }
}; };
// change code below this line // Change code below this line
ReactDOM.render(<TypesOfFood />, document.getElementById('challenge-node')); ReactDOM.render(<TypesOfFood />, document.getElementById('challenge-node'));
``` ```

View File

@ -18,7 +18,7 @@ In this challenge, you'll set up a child component to make rendering decisions b
<section id='instructions'> <section id='instructions'>
The code editor has two components that are partially defined for you: a parent called <code>GameOfChance</code>, and a child called <code>Results</code>. They are used to create a simple game where the user presses a button to see if they win or lose. The code editor has two components that are partially defined for you: a parent called <code>GameOfChance</code>, and a child called <code>Results</code>. They are used to create a simple game where the user presses a button to see if they win or lose.
First, you'll need a simple expression that randomly returns a different value every time it is run. You can use <code>Math.random()</code>. This method returns a value between <code>0</code> (inclusive) and <code>1</code> (exclusive) each time it is called. So for 50/50 odds, use <code>Math.random() >= .5</code> in your expression. Statistically speaking, this expression will return <code>true</code> 50% of the time, and <code>false</code> the other 50%. On line 30, replace the comment with this expression to complete the variable declaration. First, you'll need a simple expression that randomly returns a different value every time it is run. You can use <code>Math.random()</code>. This method returns a value between <code>0</code> (inclusive) and <code>1</code> (exclusive) each time it is called. So for 50/50 odds, use <code>Math.random() >= .5</code> in your expression. Statistically speaking, this expression will return <code>true</code> 50% of the time, and <code>false</code> the other 50%. On line 30, replace the comment with this expression to complete the variable declaration.
Now you have an expression that you can use to make a randomized decision in the code. Next you need to implement this. Render the <code>Results</code> component as a child of <code>GameOfChance</code>, and pass in <code>expression</code> as a prop called <code>fiftyFifty</code>. In the <code>Results</code> component, write a ternary expression to render the text <code>"You Win!"</code> or <code>"You Lose!"</code> based on the <code>fiftyFifty</code> prop that's being passed in from <code>GameOfChance</code>. Finally, make sure the <code>handleClick()</code> method is correctly counting each turn so the user knows how many times they've played. This also serves to let the user know the component has actually updated in case they win or lose twice in a row. Now you have an expression that you can use to make a randomized decision in the code. Next you need to implement this. Render the <code>Results</code> component as a child of <code>GameOfChance</code>, and pass in <code>expression</code> as a prop called <code>fiftyFifty</code>. In the <code>Results</code> component, write a ternary expression to render the <code>h1</code> element with the text <code>"You Win!"</code> or <code>"You Lose!"</code> based on the <code>fiftyFifty</code> prop that's being passed in from <code>GameOfChance</code>. Finally, make sure the <code>handleClick()</code> method is correctly counting each turn so the user knows how many times they've played. This also serves to let the user know the component has actually updated in case they win or lose twice in a row.
</section> </section>
## Tests ## Tests
@ -186,7 +186,9 @@ class Results extends React.Component {
super(props); super(props);
} }
render() { render() {
return <h1>{/* change code here */}</h1>; {/* Change code below this line */}
return <h1></h1>;
{/* Change code above this line */}
} }
} }
@ -200,17 +202,17 @@ class GameOfChance extends React.Component {
} }
handleClick() { handleClick() {
this.setState({ this.setState({
counter: 0 // change code here counter: 0 // Change this line
}); });
} }
render() { render() {
const expression = null; // change code here const expression = null; // Change this line
return ( return (
<div> <div>
<button onClick={this.handleClick}>Play Again</button> <button onClick={this.handleClick}>Play Again</button>
{/* change code below this line */} {/* Change code below this line */}
{/* change code above this line */} {/* Change code above this line */}
<p>{'Turn: ' + this.state.counter}</p> <p>{'Turn: ' + this.state.counter}</p>
</div> </div>
); );

View File

@ -48,7 +48,7 @@ const JSX = (
<p>Lets render this to the DOM</p> <p>Lets render this to the DOM</p>
</div> </div>
); );
// change code below this line // Change code below this line
``` ```
@ -69,7 +69,7 @@ const JSX = (
<p>Lets render this to the DOM</p> <p>Lets render this to the DOM</p>
</div> </div>
); );
// change code below this line // Change code below this line
ReactDOM.render(JSX, document.getElementById('challenge-node')); ReactDOM.render(JSX, document.getElementById('challenge-node'));
``` ```

View File

@ -45,7 +45,7 @@ class App extends React.Component {
} }
}; };
// change code below this line // Change code below this line
``` ```
@ -85,7 +85,7 @@ class App extends React.Component {
} }
}; };
// change code below this line // Change code below this line
ReactDOMServer.renderToString(<App/>); ReactDOMServer.renderToString(<App/>);
``` ```

View File

@ -49,14 +49,14 @@ class MyComponent extends React.Component {
} }
} }
render() { render() {
// change code below this line // Change code below this line
// change code above this line // Change code above this line
return ( return (
<div> <div>
{ /* change code below this line */ } { /* Change code below this line */ }
{ /* change code above this line */ } { /* Change code above this line */ }
</div> </div>
); );
} }
@ -90,14 +90,14 @@ class MyComponent extends React.Component {
} }
} }
render() { render() {
// change code below this line // Change code below this line
const name = this.state.name; const name = this.state.name;
// change code above this line // Change code above this line
return ( return (
<div> <div>
{ /* change code below this line */ } { /* Change code below this line */ }
<h1>{name}</h1> <h1>{name}</h1>
{ /* change code above this line */ } { /* Change code above this line */ }
</div> </div>
); );
} }

View File

@ -53,9 +53,9 @@ class MyComponent extends React.Component {
render() { render() {
return ( return (
<div> <div>
{ /* change code below this line */ } { /* Change code below this line */ }
{ /* change code above this line */ } { /* Change code above this line */ }
</div> </div>
); );
} }
@ -91,9 +91,9 @@ class MyComponent extends React.Component {
render() { render() {
return ( return (
<div> <div>
{ /* change code below this line */ } { /* Change code below this line */ }
<h1>{this.state.name}</h1> <h1>{this.state.name}</h1>
{ /* change code above this line */ } { /* Change code above this line */ }
</div> </div>
); );
} }

View File

@ -55,7 +55,7 @@ class MyComponent extends React.Component {
})); }));
} }
render() { render() {
// change code below this line // Change code below this line
return ( return (
<div> <div>
@ -100,7 +100,7 @@ class MyComponent extends React.Component {
})); }));
} }
render() { render() {
// change code below this line // Change code below this line
if (this.state.display) { if (this.state.display) {
return ( return (
<div> <div>

View File

@ -56,7 +56,7 @@ class CampSite extends React.Component {
); );
} }
}; };
// change code below this line // Change code below this line
``` ```
@ -101,7 +101,7 @@ class CampSite extends React.Component {
); );
} }
}; };
// change code below this line // Change code below this line
const Camper = (props) => { const Camper = (props) => {
return ( return (

View File

@ -58,9 +58,9 @@ class MyComponent extends React.Component {
this.handleClick = this.handleClick.bind(this); this.handleClick = this.handleClick.bind(this);
} }
handleClick() { handleClick() {
// change code below this line // Change code below this line
// change code above this line // Change code above this line
} }
render() { render() {
return ( return (
@ -101,11 +101,11 @@ class MyComponent extends React.Component {
this.handleClick = this.handleClick.bind(this); this.handleClick = this.handleClick.bind(this);
} }
handleClick() { handleClick() {
// change code below this line // Change code below this line
this.setState({ this.setState({
name: 'React Rocks!' name: 'React Rocks!'
}); });
// change code above this line // Change code above this line
} }
render() { render() {
return ( return (

View File

@ -56,7 +56,7 @@ class MyComponent extends React.Component {
})); }));
} }
render() { render() {
// change code below this line // Change code below this line
return ( return (
<div> <div>
<button onClick={this.toggleDisplay}>Toggle Display</button> <button onClick={this.toggleDisplay}>Toggle Display</button>
@ -100,7 +100,7 @@ class MyComponent extends React.Component {
})); }));
} }
render() { render() {
// change code below this line // Change code below this line
return ( return (
<div> <div>
<button onClick={this.toggleDisplay}>Toggle Display</button> <button onClick={this.toggleDisplay}>Toggle Display</button>

View File

@ -154,9 +154,9 @@ const inputStyle = {
class CheckUserAge extends React.Component { class CheckUserAge extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
// change code below this line // Change code below this line
// change code above this line // Change code above this line
this.submit = this.submit.bind(this); this.submit = this.submit.bind(this);
this.handleChange = this.handleChange.bind(this); this.handleChange = this.handleChange.bind(this);
} }
@ -185,7 +185,9 @@ class CheckUserAge extends React.Component {
onChange={this.handleChange} onChange={this.handleChange}
/> />
<br /> <br />
{/* change code here */} {/* Change code below this line */}
{/* Change code above this line */}
</div> </div>
); );
} }

View File

@ -175,7 +175,7 @@ class MagicEightBall extends React.Component {
'Outlook not so good', 'Outlook not so good',
'Very doubtful' 'Very doubtful'
]; ];
const answer = 'change me!'; // << change code here const answer = 'change me!'; // Change this line
return ( return (
<div> <div>
<input <input
@ -189,9 +189,9 @@ class MagicEightBall extends React.Component {
<br /> <br />
<h3>Answer:</h3> <h3>Answer:</h3>
<p> <p>
{/* change code below this line */} {/* Change code below this line */}
{/* change code above this line */} {/* Change code above this line */}
</p> </p>
</div> </div>
); );

View File

@ -139,8 +139,8 @@ class MyComponent extends React.Component {
}; };
} }
render() { render() {
const usersOnline = null; // change code here const usersOnline = null; // Change this line
const renderOnline = null; // change code here const renderOnline = null; // Change this line
return ( return (
<div> <div>
<h1>Current Online Users:</h1> <h1>Current Online Users:</h1>

View File

@ -109,9 +109,9 @@ const textAreaStyles = {
class MyToDoList extends React.Component { class MyToDoList extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
// change code below this line // Change code below this line
// change code above this line // Change code above this line
this.handleSubmit = this.handleSubmit.bind(this); this.handleSubmit = this.handleSubmit.bind(this);
this.handleChange = this.handleChange.bind(this); this.handleChange = this.handleChange.bind(this);
} }
@ -127,7 +127,7 @@ class MyToDoList extends React.Component {
}); });
} }
render() { render() {
const items = null; // change code here const items = null; // Change this line
return ( return (
<div> <div>
<textarea <textarea

View File

@ -43,7 +43,7 @@ const ShoppingCart = (props) => {
</div> </div>
) )
}; };
// change code below this line // Change code below this line
``` ```
@ -74,7 +74,7 @@ const ShoppingCart = (props) => {
) )
}; };
// change code below this line // Change code below this line
ShoppingCart.defaultProps = { ShoppingCart.defaultProps = {
items: 0 items: 0
} }

View File

@ -49,9 +49,9 @@ const Items = (props) => {
return <h1>Current Quantity of Items in Cart: {props.quantity}</h1> return <h1>Current Quantity of Items in Cart: {props.quantity}</h1>
}; };
// change code below this line // Change code below this line
// change code above this line // Change code above this line
Items.defaultProps = { Items.defaultProps = {
quantity: 0 quantity: 0
@ -101,11 +101,11 @@ const Items = (props) => {
return <h1>Current Quantity of Items in Cart: {props.quantity}</h1> return <h1>Current Quantity of Items in Cart: {props.quantity}</h1>
}; };
// change code below this line // Change code below this line
Items.propTypes = { Items.propTypes = {
quantity: PropTypes.number.isRequired quantity: PropTypes.number.isRequired
}; };
// change code above this line // Change code above this line
Items.defaultProps = { Items.defaultProps = {
quantity: 0 quantity: 0

View File

@ -58,9 +58,9 @@ const TypesOfFruit = () => {
const Fruits = () => { const Fruits = () => {
return ( return (
<div> <div>
{ /* change code below this line */ } { /* Change code below this line */ }
{ /* change code above this line */ } { /* Change code above this line */ }
</div> </div>
); );
}; };
@ -74,9 +74,9 @@ class TypesOfFood extends React.Component {
return ( return (
<div> <div>
<h1>Types of Food:</h1> <h1>Types of Food:</h1>
{ /* change code below this line */ } { /* Change code below this line */ }
{ /* change code above this line */ } { /* Change code above this line */ }
</div> </div>
); );
} }
@ -119,9 +119,9 @@ const TypesOfFruit = () => {
const Fruits = () => { const Fruits = () => {
return ( return (
<div> <div>
{ /* change code below this line */ } { /* Change code below this line */ }
<TypesOfFruit /> <TypesOfFruit />
{ /* change code above this line */ } { /* Change code above this line */ }
</div> </div>
); );
}; };
@ -135,9 +135,9 @@ class TypesOfFood extends React.Component {
return ( return (
<div> <div>
<h1>Types of Food:</h1> <h1>Types of Food:</h1>
{ /* change code below this line */ } { /* Change code below this line */ }
<Fruits /> <Fruits />
{ /* change code above this line */ } { /* Change code above this line */ }
</div> </div>
); );
} }

View File

@ -97,13 +97,13 @@ class MyComponent extends React.Component {
this.state = { this.state = {
visibility: false visibility: false
}; };
// change code below this line // Change code below this line
// change code above this line // Change code above this line
} }
// change code below this line // Change code below this line
// change code above this line // Change code above this line
render() { render() {
if (this.state.visibility) { if (this.state.visibility) {
return ( return (

View File

@ -16,7 +16,7 @@ The best practice with React is to place API calls or any calls to your server i
## Instructions ## Instructions
<section id='instructions'> <section id='instructions'>
There is a mock API call in <code>componentDidMount()</code>. It sets state after 2.5 seconds to simulate calling a server to retrieve data. This example requests the current total active users for a site. In the render method, render the value of <code>activeUsers</code> in the <code>h1</code>. Watch what happens in the preview, and feel free to change the timeout to see the different effects. There is a mock API call in <code>componentDidMount()</code>. It sets state after 2.5 seconds to simulate calling a server to retrieve data. This example requests the current total active users for a site. In the render method, render the value of <code>activeUsers</code> in the <code>h1</code> after the text <code>Active Users: </code>. Watch what happens in the preview, and feel free to change the timeout to see the different effects.
</section> </section>
## Tests ## Tests
@ -71,7 +71,9 @@ class MyComponent extends React.Component {
render() { render() {
return ( return (
<div> <div>
<h1>Active Users: {/* change code here */}</h1> {/* Change code below this line */}
<h1>Active Users: </h1>
{/* Change code below this line */}
</div> </div>
); );
} }

View File

@ -52,9 +52,9 @@ class MyComponent extends React.Component {
super(props); super(props);
} }
componentWillMount() { componentWillMount() {
// change code below this line // Change code below this line
// change code above this line // Change code above this line
} }
render() { render() {
return <div /> return <div />
@ -86,9 +86,9 @@ class MyComponent extends React.Component {
super(props); super(props);
} }
componentWillMount() { componentWillMount() {
// change code below this line // Change code below this line
console.log('Component is mounting...'); console.log('Component is mounting...');
// change code above this line // Change code above this line
} }
render() { render() {
return <div /> return <div />

View File

@ -40,7 +40,7 @@ tests:
<div id='jsx-seed'> <div id='jsx-seed'>
```jsx ```jsx
// change code below this line // Change code below this line
``` ```
@ -55,7 +55,7 @@ tests:
```js ```js
// change code below this line // Change code below this line
class MyComponent extends React.Component { class MyComponent extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);

View File

@ -49,13 +49,13 @@ class Counter extends React.Component {
this.state = { this.state = {
count: 0 count: 0
}; };
// change code below this line // Change code below this line
// change code above this line // Change code above this line
} }
// change code below this line // Change code below this line
// change code above this line // Change code above this line
render() { render() {
return ( return (
<div> <div>

View File

@ -83,7 +83,7 @@ const authReducer = (state = {authenticated: false}, action) => {
} }
}; };
const rootReducer = // define the root reducer here const rootReducer = // Define the root reducer here
const store = Redux.createStore(rootReducer); const store = Redux.createStore(rootReducer);

View File

@ -52,7 +52,7 @@ const defaultState = {
const immutableReducer = (state = defaultState, action) => { const immutableReducer = (state = defaultState, action) => {
switch(action.type) { switch(action.type) {
case 'ONLINE': case 'ONLINE':
// don't mutate state here or the tests will fail // Don't mutate state here or the tests will fail
return return
default: default:
return state; return state;

View File

@ -48,7 +48,6 @@ const reducer = (state = 5) => {
// For example: Redux.createStore() // For example: Redux.createStore()
// Define the store here: // Define the store here:
``` ```
</div> </div>
@ -66,10 +65,6 @@ const reducer = (state = 5) => {
return state; return state;
} }
// Redux methods are available from a Redux object
// For example: Redux.createStore()
// Define the store here:
const store = Redux.createStore(reducer); const store = Redux.createStore(reducer);
``` ```

View File

@ -59,7 +59,6 @@ const action = {
const action = { const action = {
type: 'LOGIN' type: 'LOGIN'
} }
// Define an action creator here:
const actionCreator = () => { const actionCreator = () => {
return action; return action;
}; };

View File

@ -80,7 +80,6 @@ const loginAction = () => {
} }
}; };
// Dispatch the action here:
store.dispatch(loginAction()); store.dispatch(loginAction());
``` ```

View File

@ -40,7 +40,7 @@ const store = Redux.createStore(
(state = 5) => state (state = 5) => state
); );
// change code below this line // Change code below this line
``` ```
@ -59,7 +59,7 @@ const store = Redux.createStore(
(state = 5) => state (state = 5) => state
); );
// change code below this line // Change code below this line
const currentState = store.getState(); const currentState = store.getState();
``` ```

View File

@ -46,9 +46,9 @@ const defaultState = {
}; };
const reducer = (state = defaultState, action) => { const reducer = (state = defaultState, action) => {
// change code below this line // Change code below this line
// change code above this line // Change code above this line
}; };
const store = Redux.createStore(reducer); const store = Redux.createStore(reducer);

View File

@ -53,14 +53,13 @@ const todos = [
const immutableReducer = (state = todos, action) => { const immutableReducer = (state = todos, action) => {
switch(action.type) { switch(action.type) {
case ADD_TO_DO: case ADD_TO_DO:
// don't mutate state here or the tests will fail // Don't mutate state here or the tests will fail
return return
default: default:
return state; return state;
} }
}; };
// an example todo argument would be 'Learn React',
const addToDo = (todo) => { const addToDo = (todo) => {
return { return {
type: ADD_TO_DO, type: ADD_TO_DO,
@ -84,7 +83,6 @@ const store = Redux.createStore(immutableReducer);
```js ```js
const ADD_TO_DO = 'ADD_TO_DO'; const ADD_TO_DO = 'ADD_TO_DO';
// A list of strings representing tasks to do:
const todos = [ const todos = [
'Go to the store', 'Go to the store',
'Clean the house', 'Clean the house',
@ -101,7 +99,6 @@ const immutableReducer = (state = todos, action) => {
} }
}; };
// an example todo argument would be 'Learn React',
const addToDo = (todo) => { const addToDo = (todo) => {
return { return {
type: ADD_TO_DO, type: ADD_TO_DO,

View File

@ -51,12 +51,12 @@ const reducer = (state = 0, action) => {
const store = Redux.createStore(reducer); const store = Redux.createStore(reducer);
// global count variable: // Global count variable:
let count = 0; let count = 0;
// change code below this line // Change code below this line
// change code above this line // Change code above this line
store.dispatch({type: ADD}); store.dispatch({type: ADD});
console.log(count); console.log(count);
@ -98,7 +98,7 @@ const reducer = (state = 0, action) => {
const store = Redux.createStore(reducer); const store = Redux.createStore(reducer);
let count = 0; let count = 0;
// change code below this line // Change code below this line
store.subscribe( () => store.subscribe( () =>
{ {
@ -106,7 +106,7 @@ store.subscribe( () =>
} }
); );
// change code above this line // Change code above this line
store.dispatch({type: ADD}); store.dispatch({type: ADD});
store.dispatch({type: ADD}); store.dispatch({type: ADD});

View File

@ -41,7 +41,7 @@ tests:
const immutableReducer = (state = [0,1,2,3,4,5], action) => { const immutableReducer = (state = [0,1,2,3,4,5], action) => {
switch(action.type) { switch(action.type) {
case 'REMOVE_ITEM': case 'REMOVE_ITEM':
// don't mutate state here or the tests will fail // Don't mutate state here or the tests will fail
return return
default: default:
return state; return state;

View File

@ -42,18 +42,18 @@ const ADD_NOTE = 'ADD_NOTE';
const notesReducer = (state = 'Initial State', action) => { const notesReducer = (state = 'Initial State', action) => {
switch(action.type) { switch(action.type) {
// change code below this line // Change code below this line
// change code above this line // Change code above this line
default: default:
return state; return state;
} }
}; };
const addNoteText = (note) => { const addNoteText = (note) => {
// change code below this line // Change code below this line
// change code above this line // Change code above this line
}; };
const store = Redux.createStore(notesReducer); const store = Redux.createStore(notesReducer);
@ -78,22 +78,22 @@ const ADD_NOTE = 'ADD_NOTE';
const notesReducer = (state = 'Initial State', action) => { const notesReducer = (state = 'Initial State', action) => {
switch(action.type) { switch(action.type) {
// change code below this line // Change code below this line
case ADD_NOTE: case ADD_NOTE:
return action.text; return action.text;
// change code above this line // Change code above this line
default: default:
return state; return state;
} }
}; };
const addNoteText = (note) => { const addNoteText = (note) => {
// change code below this line // Change code below this line
return { return {
type: ADD_NOTE, type: ADD_NOTE,
text: note text: note
} }
// change code above this line // Change code above this line
}; };
const store = Redux.createStore(notesReducer); const store = Redux.createStore(notesReducer);

View File

@ -50,9 +50,9 @@ const defaultState = {
}; };
const authReducer = (state = defaultState, action) => { const authReducer = (state = defaultState, action) => {
// change code below this line // Change code below this line
// change code above this line // Change code above this line
}; };
const store = Redux.createStore(authReducer); const store = Redux.createStore(authReducer);

View File

@ -49,9 +49,9 @@ tests:
<div id='jsx-seed'> <div id='jsx-seed'>
```jsx ```jsx
// change code below this line // Change code below this line
// change code above this line // Change code above this line
const defaultState = { const defaultState = {
authenticated: false authenticated: false

View File

@ -53,13 +53,13 @@ const receivedData = (data) => { return {type: RECEIVED_DATA, users: data.users}
const handleAsync = () => { const handleAsync = () => {
return function(dispatch) { return function(dispatch) {
// dispatch request action here // Dispatch request action here
setTimeout(function() { setTimeout(function() {
let data = { let data = {
users: ['Jeff', 'William', 'Alice'] users: ['Jeff', 'William', 'Alice']
} }
// dispatch received data action here // Dispatch received data action here
}, 2500); }, 2500);
} }

View File

@ -45,7 +45,7 @@ tests:
const immutableReducer = (state = ['Do not mutate state!'], action) => { const immutableReducer = (state = ['Do not mutate state!'], action) => {
switch(action.type) { switch(action.type) {
case 'ADD_TO_DO': case 'ADD_TO_DO':
// don't mutate state here or the tests will fail // Don't mutate state here or the tests will fail
return return
default: default:
return state; return state;

View File

@ -44,16 +44,16 @@ tests:
<div id='jsx-seed'> <div id='jsx-seed'>
```jsx ```jsx
const INCREMENT = null; // define a constant for increment action types const INCREMENT = null; // Define a constant for increment action types
const DECREMENT = null; // define a constant for decrement action types const DECREMENT = null; // Define a constant for decrement action types
const counterReducer = null; // define the counter reducer which will increment or decrement the state based on the action it receives const counterReducer = null; // Define the counter reducer which will increment or decrement the state based on the action it receives
const incAction = null; // define an action creator for incrementing const incAction = null; // Define an action creator for incrementing
const decAction = null; // define an action creator for decrementing const decAction = null; // Define an action creator for decrementing
const store = null; // define the Redux store here, passing in your reducers const store = null; // Define the Redux store here, passing in your reducers
``` ```
</div> </div>