I checked if I had unclosed tags, parens and curly braces. No issue there to me.
I set up my node and react environment and have localhost:3000 up and running. No issue here to me.
But I don't know where to look anymore. Any idea, please? Thanks for your help.
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
addLevel1Num1: 1,
addLevel1Num2: 1,
subLevel1Num1: 1,
subLevel1Num2: 1,
addLevel2Num1: 1,
addLevel2Num2: 1,
subLevel2Num1: 20,
subLevel2Num2: 20,
response: "",
incorrect: false,
score: 0,
// scoreSubLevel1: 3
};
}
}
class ProblemAddLevel1 extends React.Component {
render() {
return (
<div>
<h1 id="mainTitle">Welcome to the Review Math Game Area!</h1>
<div id="problem" className={this.state.incorrect ? "incorrect" : ""}>
{this.state.addLevel1Num1} + {this.state.addLevel1Num2} = <input onKeyPress={this.inputKeyPressAddLevel1} onChange={this.updateResponse} value={this.state.response} class="resizedTextBox"/>
Score: {this.state.score} <button onClick={this.resetLineAddLevel1} class="btn btn-primary">Reset Line</button> <button onClick={this.resetFullGame} class="btn btn-primary">Reset Full Game</button>
</div>
</div>
);
}
}
.... similar code as above skipped.
render() {
if (this.state.score < 3) {
return <ProblemAddLevel1 />;
}
if (this.state.score < 6) {
return <ProblemSubLevel1 />;
}
if (this.state.score < 9) {
return <ProblemAddLevel2 />;
}
if (this.state.score < 15) {
return <ProblemSubLevel1 />;
}
if (this.state.score === 15) {
return <WinRace />;
}
}
....
ReactDOM.render((
<div>
<App />
<ProblemAddLevel1 />
<ProblemSubLevel1 />
<ProblemAddLevel2 />
<ProblemSubLevel1 />
<WinRace />
</div>
), document.querySelector("#app"));
I get this error in the browser:
Failed to compile
./src/App.js
Line 109: Parsing error: Unexpected token, expected ";"
107 |
108 |
> 109 | render() {
| ^
110 | if (this.state.score < 3) {
111 | return <ProblemAddLevel1 />;
112 | }
This error occurred during the build time and cannot be dismissed.
I REWORKED ON THIS ISSUE TODAY LOOKING FOR FIXES AND GOT SOMETHING ELSE:
APP.JS
import React, { Component } from "react";
import ReactDOM from "react-dom";
import './index.js';
import './index.css';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
addLevel1Num1: 1,
addLevel1Num2: 1,
subLevel1Num1: 1,
subLevel1Num2: 1,
addLevel2Num1: 1,
addLevel2Num2: 1,
subLevel2Num1: 20,
subLevel2Num2: 20,
response: "",
incorrect: false,
score: 0,
// scoreSubLevel1: 3
};
}
render() {
if (this.state.score < 3) {
return <ProblemAddLevel1 />;
}
if (this.state.score < 6) {
return <ProblemSubLevel1 />;
}
if (this.state.score < 9) {
return <ProblemAddLevel2 />;
}
if (this.state.score < 15) {
return <ProblemSubLevel1 />;
}
if (this.state.score === 15) {
return <WinRace />;
}
}
default export App;
}
class ProblemAddLevel1 extends React.Component {
render() {
return (
<div>
<h1 id="mainTitle">Welcome to the Review Math Game Area!</h1>
<div id="problem" className={this.state.incorrect ? "incorrect" : ""}>
{this.state.addLevel1Num1} + {this.state.addLevel1Num2} = <input onKeyPress={this.inputKeyPressAddLevel1} onChange={this.updateResponse} value={this.state.response} class="resizedTextBox"/>
Score: {this.state.score} <button onClick={this.resetLineAddLevel1} class="btn btn-primary">Reset Line</button> <button onClick={this.resetFullGame} class="btn btn-primary">Reset Full Game</button>
</div>
</div>
);
}
}
class ProblemSubLevel1 extends React.Component {
render() {
return (
<div>
<h1 id="mainTitle">Welcome to the Review Math Game Area!</h1>
<div id="problem" className={this.state.incorrect ? "incorrect" : ""}>
{this.state.subLevel1Num1} - {this.state.subLevel1Num2} = <input onKeyPress={this.inputKeyPressSubLevel1} onChange={this.updateResponse} value={this.state.response} class="resizedTextBox"/>
Score: {this.state.score} <button onClick={this.resetLineSubLevel1} class="btn btn-primary">Reset Line</button> <button onClick={this.resetFullGame} class="btn btn-primary">Reset Full Game</button>
<img id="green-leaf" src={'./green-leaf.svg'} />
</div>
</div>
);
}
}
class ProblemAddLevel2 extends React.Component {
render() {
return (
<div>
<h1 id="mainTitle">Welcome to the Review Math Game Area!</h1>
<div id="problem" className={this.state.incorrect ? "incorrect" : ""}>
{this.state.addLevel2Num1} + {this.state.addLevel2Num2} = <input onKeyPress={this.inputKeyPressAddLevel2} onChange={this.updateResponse} value={this.state.response} class="resizedTextBox"/>
Score: {this.state.score} <button onClick={this.resetLineAddLevel2} class="btn btn-primary">Reset Line</button> <button onClick={this.resetFullGame} class="btn btn-primary">Reset Full Game</button>
<img id="green-leaf" src={'./green-leaf.svg'} />
<img id="green-leaf" src={'./green-leaf.svg'} />
</div>
</div>
);
}
}
class ProblemSubLevel2 extends React.Component {
render() {
return (
<div>
<h1 id="mainTitle">Welcome to the Review Math Game Area!</h1>
<div id="problem" className={this.state.incorrect ? "incorrect" : ""}>
{this.state.subLevel2Num1} - {this.state.subLevel2Num2} = <input onKeyPress={this.inputKeyPressSubLevel2} onChange={this.updateResponse} value={this.state.response} class="resizedTextBox"/>
Score: {this.state.score} <button onClick={this.resetLineSubLevel2} class="btn btn-primary">Reset Line</button> <button onClick={this.resetFullGame} class="btn btn-primary">Reset Full Game</button>
<img id="green-leaf" src={'./green-leaf.svg'} />
<img id="green-leaf" src={'./green-leaf.svg'} />
<img id="green-leaf" src={'./green-leaf.svg'} />
</div>
</div>
);
}
}
class WinRace extends React.Component {
render() {
return (
<div>
<h1 id="mainTitle">Well done! You won the Four Green Leaves Title!</h1>
<div id="problem" className={this.state.incorrect ? "incorrect" : ""}>
Score: {this.state.score}
<img id="green-leaf" src={'./green-leaf.svg'} />
<img id="green-leaf" src={'./green-leaf.svg'} />
<img id="green-leaf" src={'./green-leaf.svg'} />
<img id="green-leaf" src={'./green-leaf.svg'} />
<h2 id="mainTitle">Come back to review your maths in a few days!</h2>
<button onClick={this.resetFullGame} class="btn btn-primary">Reset Full Game</button>
</div>
</div>
);
}
}
updateResponse = (event) => {
this.setState({ response: event.target.value });
}
inputKeyPressAddLevel1 = (event) => {
if (event.key === "Enter") {
const answer = parseInt(this.state.response);
if (answer === this.state.addLevel1Num1 + this.state.addLevel1Num2) {
this.setState(state => ({
addLevel1Num1: Math.ceil(Math.random() * 10) + state.score,
addLevel1Num2: Math.ceil(Math.random() * 10) + state.score,
// subLevel1Num1: Math.ceil(Math.random() * 10) + state.scoreSubLevel1,
// subLevel1Num2: Math.ceil(Math.random() * 10) + state.scoreSubLevel2,
response: "",
incorrect: false,
score: state.score + 1
}));
} else {
this.setState({
response: "",
incorrect: true
});
}
}
}
inputKeyPressSubLevel1 = (event) => {
if (event.key === "Enter") {
const answer = parseInt(this.state.response);
if (answer === this.state.subLevel1Num1 - this.state.subLevel1Num2) {
this.setState(state => ({
subLevel1Num1: Math.ceil(Math.random() * 10) + state.score,
subLevel1Num2: Math.ceil(Math.random() * 10) + state.score,
response: "",
incorrect: false,
score: state.score + 1
}));
} else {
this.setState({
response: "",
incorrect: true
});
}
}
}
inputKeyPressAddLevel2 = (event) => {
if (event.key === "Enter") {
const answer = parseInt(this.state.response);
if (answer === this.state.addLevel2Num1 + this.state.addLevel2Num2) {
this.setState(state => ({
addLevel2Num1: (Math.ceil(Math.random() * 10)) * 2 + state.score,
addLevel2Num2: (Math.ceil(Math.random() * 10)) * 2 + state.score,
// subLevel1Num1: Math.ceil(Math.random() * 10) + state.scoreSubLevel1,
// subLevel1Num2: Math.ceil(Math.random() * 10) + state.scoreSubLevel2,
response: "",
incorrect: false,
score: state.score + 1
}));
} else {
this.setState({
response: "",
incorrect: true
});
}
}
}
inputKeyPressSubLevel2 = (event) => {
if (event.key === "Enter") {
const answer = parseInt(this.state.response);
if (answer === this.state.subLevel2Num1 - this.state.subLevel2Num2) {
this.setState(state => ({
subLevel2Num1: Math.ceil(Math.random() * 10) + state.score,
subLevel2Num2: Math.ceil(Math.random() * 10) + state.score,
response: "",
incorrect: false,
score: state.score + 1
}));
} else {
this.setState({
response: "",
incorrect: true
});
}
}
}
resetFullGame = (event) => {
this.setState({
addLevel1Num1: 1,
addLevel1Num2: 1,
subLevel1Num1: 1,
subLevel1Num2: 1,
addLevel2Num1: 1,
addLevel2Num2: 1,
subLevel2Num1: 1,
subLevel2Num2: 1,
response: "",
incorrect: false,
score: 0,
// scoreSubLevel1: 0
});
}
resetLineAddLevel1 = (event) => {
this.setState({
addLevel1Num1: 1,
addLevel1Num2: 1,
response: "",
incorrect: false
});
}
resetLineSubLevel1 = (event) => {
this.setState({
subLevel1Num1: 1,
subLevel1Num2: 1,
response: "",
incorrect: false
});
}
resetLineAddLevel2 = (event) => {
this.setState({
addLevel2Num1: 1,
addLevel2Num2: 1,
response: "",
incorrect: false
});
}
resetLineSubLevel1 = (event) => {
this.setState({
subLevel2Num1: 20,
subLevel2Num2: 20,
response: "",
incorrect: false
});
}
ReactDOM.render((
<div>
<App />
<ProblemAddLevel1 />
<ProblemSubLevel1 />
<ProblemAddLevel2 />
<ProblemSubLevel1 />
<WinRace />
</div>
), document.querySelector("#app"));
INDEX.JS
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App.js';
import * as serviceWorker from './serviceWorker';
ReactDOM.render(<App />, document.getElementById('root'));
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers:
serviceWorker.unregister();
//export {default} from App;