Newbie up against a wall

Hey guys. I just stared going through the examples in the Getting Started book. I am on example 4-3 where you are programming to turn on LED when button is pressed and keep it on after released.

I'm sure I did something wrong, but I have been going over the same line all day and I can figure what.

here is the sketch

const int LED=13;//13 is the pin for the led
const int BUTTON=7;// 7 is the input pin for the button
int val=0;//val will be used to store the state of the input pin
void setup() {
pinMode(LED, OUTPUT);//LED is an output
pinMode (BUTTON, INPUT); //BUTTON is an input
}

void loop() {
val=digitalRead(BUTTON);//READ INPUT VALUE AND STORE IT CHECK WHETHER INPUT VALUE IS HIGH (BUTTON PRESSED)
if (val == HIGH){
state = 1 - state;
}
if (state == 1){
digitalWrite(LED, HIGH);//TURNS LED ON
}else{
digitalWrite(LED,LOW);
}
}

The error message is:Arduino: 1.6.5 (Windows 7), Board: "Arduino/Genuino Uno"

PUSHBUTTONCONTROLMAINTAIN.ino: In function 'void loop()':
PUSHBUTTONCONTROLMAINTAIN:12: error: 'state' was not declared in this scope
PUSHBUTTONCONTROLMAINTAIN:14: error: 'state' was not declared in this scope
'state' was not declared in this scope

It is highlighting if (state == 1){

Like I said I am comparing it to the example in the book and it looks verbatim to me. I searched the forum to see if someone else had the same issue but could find nothing. Thanks for your help.

You are using a variable called state that you don't seem to have defined anywhere.

Ok I see it now. Thanks man. Like I said I'm a noob

also this line seems wrong

state = 1 - state; //that means state equals state minus one which would not be one.

should be

state = 1;

gpop1:
also this line seems wrong

state = 1 - state; //that means state equals state minus one which would not be one.

should be

state = 1;

This is OK. It basically toggles state back and forth between 0 and 1. When it is 0, 1 - 0 is 1. When it is 1, 1-1 is 0.

Delta_G:
This is OK. It basically toggles state back and forth between 0 and 1. When it is 0, 1 - 0 is 1. When it is 1, 1-1 is 0.

my bad I read it backwards as in state=state-1....ops