I’m having trouble passing it. When I use true, it’s missing one test. I read a few posts to use ‘false’ instead but when I do, it makes a build error. What’s going on?
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
display: true
}
this.toggleDisplay = this.toggleDisplay.bind(this);
}
toggleDisplay() {
this.setState({
display: !this.state.display
});
}
render() {
// change code below this line
if (this.state.display == true) {
return (
<div>
<button onClick={this.toggleDisplay}>Toggle Display</button>
<h1>Displayed!</h1>
</div>
);
} else {
return(
<div>
<button onClick = {this.toggle.display}>Toggle Display</button>
</div>
);
}
}
};
I believe they ask for something like this:
if(true){
return ( <div>
<button onClick={this.toggleDisplay}>
Toggle Display</button>
<h1>Displayed!</h1>
</div>
);
}
else{
//not h1
}
Okay I’ll try that out.
Edit: what would I add after the ‘else’?
miku86
August 18, 2020, 8:03am
4
Hey there,
nice to meet you!
I’ve edited your post for readability, because it was very hard to read.
You can use the “preformatted text” tool in the editor ( </>
) to add code.
In the future, please use the Get Help
button in a lesson to create a forum topic and fill in the questions.
Thanks for understanding!
miku86
August 18, 2020, 8:04am
5
What does the lesson tasks want you to do?
They just want a div and button. However, when I have it in, it won’t pass the test.
miku86
August 18, 2020, 12:58pm
7
In your button, you are using this.toggle.display
.
Where does this come from?
And please do not post images of your code,
use the “preformatted text” tool,
because then we can copy and paste your code.
I used it in the last lesson, use advanced javascript in react render. I also saw it in the part where we’re not supposed to change it.
And I found that reformatted button.
miku86
August 19, 2020, 12:52pm
9
Can you show us this line?
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
display: true
}
this.toggleDisplay = this.toggleDisplay.bind(this);
}
toggleDisplay() {
this.setState({
display: !this.state.display
});
}
render() {
// change code below this line
if (this.state.display == true) {
return (
<div>
<button onClick={this.toggleDisplay}>Toggle Display</button>
<h1>Displayed!</h1>
</div>
);
} else {
return(
<div>
<button onClick = {this.toggle.display}>Toggle Display</button>
</div>
);
}
}
};
miku86
August 20, 2020, 1:08pm
11
I asked for the line this.toggle.display
and your answer was
But you wrote the stuff yourself.
When you reset the code, you will see the starting code.
Here’s the code that was reset. I don’t know how to highlight on here or I would show you.
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
display: true
}
this.toggleDisplay = this.toggleDisplay.bind(this);
}
toggleDisplay() {
this.setState((state) => ({
display: !state.display
}));
}
render() {
// change code below this line
return (
<div>
<button onClick={this.toggleDisplay}>Toggle Display</button>
<h1>Displayed!</h1>
</div>
);
}
};
miku86
August 20, 2020, 3:50pm
13
What do you want to show?
There is no this.toggle.display
,
there is only this.toggleDisplay
.
Oh. That looks like a typo.
1 Like