-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
129 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React from 'react'; | ||
import Question from '../Question'; | ||
import Answer from '../Answer'; | ||
import Score from '../Score'; | ||
import Previous from '../Previous'; | ||
import RightButton from '../RightButton'; | ||
|
||
export default class Game extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
questionNum: 0, | ||
score: 0, | ||
numAnswered: 0, | ||
length: 10, | ||
}; | ||
this.changeQNum = this.changeQNum.bind(this); | ||
this.incrementScore = this.incrementScore.bind(this); | ||
this.incrementNumAnswered = this.incrementNumAnswered.bind(this); | ||
} | ||
|
||
|
||
changeQNum(increment) { | ||
const newQ = this.state.questionNum + increment; | ||
if (newQ >= 0 && newQ < this.state.length) { | ||
this.setState({ questionNum: newQ }); | ||
} | ||
} | ||
|
||
incrementScore() { | ||
this.setState({ score: this.state.score + 1 }); | ||
sessionStorage.setItem("score", this.state.score + 1); | ||
} | ||
|
||
incrementNumAnswered() { | ||
this.setState({ numAnswered: this.state.numAnswered + 1 }); | ||
sessionStorage.setItem("numAnswered", this.state.numAnswered + 1); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div className='panel'> | ||
<h3><Question questionNumber={this.state.questionNum} /></h3> | ||
<Answer questionNum={this.state.questionNum} | ||
incrementScore={this.incrementScore} | ||
incrementNumAnswered={this.incrementNumAnswered} | ||
numAnswered={this.state.numAnswered} /> | ||
<div className='nav'> | ||
<Previous onClick={this.changeQNum} /> | ||
<Score numAnswered={this.state.numAnswered} | ||
score={this.state.score} /> | ||
<RightButton onClick={this.changeQNum} | ||
numAnswered={this.state.numAnswered} | ||
questionNum={this.state.questionNum} | ||
length={this.state.length} /> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
|
||
const Results = () => { | ||
let score = sessionStorage.getItem("score"); | ||
if (score === null){ | ||
score = 0; | ||
} | ||
return ( | ||
<div className = 'results-container'> | ||
<h2 className = 'results-text'>Thanks for playing! <br/> Here was your final score: {score}/{sessionStorage.getItem("numAnswered")}</h2> | ||
</div> | ||
|
||
) | ||
} | ||
|
||
export default Results |