diff --git a/src/App.js b/src/App.js
index e3be8c5..6e1bdf7 100644
--- a/src/App.js
+++ b/src/App.js
@@ -14,6 +14,7 @@ class App extends React.Component {
this.state = {
gifs: [],
mysteryWord: "",
+ attempt: 0,
};
}
@@ -38,18 +39,29 @@ class App extends React.Component {
this.setState({
mysteryWord,
gifs,
+ attempt: 0,
});
};
+ handlePlayerAnswer = (playerAnswer) => {
+ const { mysteryWord, attempt } = this.state;
+ if (playerAnswer === mysteryWord) {
+ alert("you win!");
+ } else {
+ this.setState({ attempt: attempt + 1 });
+ alert("you lose...");
+ }
+ };
+
render() {
- const { gifs, mysteryWord } = this.state;
+ const { gifs, attempt } = this.state;
return (
);
}
diff --git a/src/components/gif_list.jsx b/src/components/gif_list.jsx
index 52bff93..56907dd 100644
--- a/src/components/gif_list.jsx
+++ b/src/components/gif_list.jsx
@@ -1,15 +1,17 @@
-import React from 'react'
-import Gif from './gif'
+import React from "react";
+import Gif from "./gif";
-class GifList extends React.Component {
- render() {
- const {gifs} = this.props;
- return (
-
- {gifs.map(({url, id}) => )}
-
- )
- }
-}
+const GifList = (props) => {
+ const { gifs, length } = props;
+ return (
+
+ {gifs.slice(0, length).map(({ url, id }) => (
+ -
+
+
+ ))}
+
+ );
+};
-export default GifList
+export default GifList;
diff --git a/src/components/player_input.jsx b/src/components/player_input.jsx
index 114be13..90f9f3e 100644
--- a/src/components/player_input.jsx
+++ b/src/components/player_input.jsx
@@ -11,10 +11,9 @@ class PlayerInput extends React.Component {
};
handleSubmit = (event) => {
- const { mysteryWord } = this.props;
+ const { handlePlayerAnswer } = this.props;
const { playerAnswer } = this.state;
- const message = mysteryWord === playerAnswer ? "you win!" : "you lose...";
- alert(message);
+ handlePlayerAnswer(playerAnswer);
event.preventDefault();
};