Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Question1-Header.js
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
/* DELETE THIS LINE AND WRITE THE ANSWER TO QUESTION 1 HERE */

import React from 'react';
/*
* ============= Question 1 =============
*
Expand Down
7 changes: 6 additions & 1 deletion src/Question2-LionsExhibit.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,11 @@

import React from "react";

const LionsExhibit = () => null;
const LionsExhibit = () => (
<article className="Lions">
<h2>Lions</h2>
<p>The mane is the most recognisable feature of the species</p>
</article>
)

export default LionsExhibit;
6 changes: 3 additions & 3 deletions src/Question3-TigersExhibit.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,12 +18,12 @@

import React from "react";

function TigersExhibit() {
function TigersExhibit(props) {
return (
<div className="tigers">
<h2>Tigers</h2>
<p>There are ... tigers in the world</p>
<ul>{/* DELETE THIS LINE AND WRITE THE ANSWER PART B HERE */}</ul>
<p>There are {props.population} tigers in the world</p>
<ul>{props.habitats.map(habit => <li key={habit}>{habit}</li>)}</ul>
</div>
);
}
Expand Down
18 changes: 9 additions & 9 deletions src/Question4-MonkeysExhibit.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,19 +4,19 @@
* Convert the MonkeysExhibit component below to a class component.
*/

import Reactfrom "react";
import React, { Component } from 'react'

function MonkeysExhibit(props) {
return (
<section className="monkeys">
<h2>Latin name: {props.latinName}</h2>
export default class MonkeyExhibit extends Component {
render() {
return (
<section className="monkeys">
<h2>Latin name: {this.props.latinName}</h2>
<ul>
{props.commonSpecies.map((speciesName, index) => {
{this.props.commonSpecies.map((speciesName, index) => {
return <li key={index}>{speciesName}</li>;
})}
</ul>
</section>
);
)
}
}

export default MonkeysExhibit;
9 changes: 7 additions & 2 deletions src/Question5-AnimalSpotter.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,9 +13,14 @@ import React, { Component } from "react";
class AnimalSpotter extends Component {
constructor(props) {
super(props);
this.state = {};
this.state = {
animalSpotted: 0
};
}

spotAnimal = () => {
this.setState(pre => ({ animalSpotted: pre.animalSpotted + 1}))
}
render() {
return (
<div className="animal-spotter">
Expand All@@ -28,7 +33,7 @@ class AnimalSpotter extends Component {

function CounterButton(props) {
return (
<button style={{ background: "lightseagreen", color: "white" }} onClick>
<button style={{ background: "lightseagreen", color: "white" }} onClick={props.handleClick}>
I spotted an animal!
</button>
);
Expand Down
24 changes: 18 additions & 6 deletions src/Question6-ImageGallery.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,18 +12,30 @@ import React, { Component } from "react";

class ImageGallery extends Component {
constructor(props) {
super(props);
super(props)
this.state = {
imgSrc: null
};
imgSrc: null,
isLoading: true
}
}

fetchData = () => {
fetch().then(res => res.json());
};
fetch("https://auspicious-baritone.glitch.me/gorilla")
.then(res => res.json())
.then(data =>
this.setState({ imgSrc: data, isLoading: false }))
}
componentDidMount() {
this.fetchData()
}


render() {
return <img src={this.state.imgSrc} alt="An animal" />;
return this.state.isLoading ? (
<span>Loading...</span>
) : (
<img src={this.state.imgSrc} alt="An animal" />
)
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/Question7-WindowSize.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,6 +27,10 @@ export class WindowSize extends Component {
componentDidMount() {
window.addEventListener("resize", this.handleWindowResize);
}
componentWillUnmount() {
window.removeEventListener("resize", this.handleWindowResize)
}


handleWindowResize = () => {
console.log("Window was resized!", window.innerWidth);
Expand Down
Loading