changing from hold to toggle

can anyone help me, how to change my code from hold to basic toggle?
here is my code:

const int switchPin=2;
const int motorPin=9;
int switchState=0;

void setup() {
pinMode(switchPin,INPUT);
pinMode(motorPin,OUTPUT);
}

void loop()
{
switchState=digitalRead(switchPin);
if(switchState==HIGH){
digitalWrite(motorPin,HIGH);
}
else{
digitalWrite(motorPin,LOW);
}
}

Have a look at the StateChangeDetection example in the IDE (File->Examples->02 Digital ->StateChangeDetection). It will show you have to successfully detect your switch changing state and then you can react to it.

What are you trying to accomplish ‘exactly’ ?

Here is a small sketch to illustrate using the state change detection method to toggle the state of a pin. Note that the switch is wired from the input (set to pinMode INPUT_PULLUP) to ground or active LOW versus the active HIGH switch in the tutorial.

// This is to illustrate using tne state change detectin method to 
// toggle the state of a pin (Pin 13, the on board LED) with
// a momentary switch (pushbutton) is wired from pin 8 to ground
// by C Goulding aka groundFungus

// this constant won't change:
const int  buttonPin = 8;    // the pin that the pushbutton is attached to
const int ledPin = 13;       // the pin that the LED is attached to
// Variables will change:
boolean buttonState = 0;         // current state of the button
boolean lastButtonState = 0;     // previous state of the button

void setup()
{
   // initialize the button pin as a input with internal pullup enabled
   pinMode(buttonPin, INPUT_PULLUP);
   // initialize the LED as an output:
   pinMode(ledPin, OUTPUT);
   // initialize serial communication:
   Serial.begin(9600);
}

void loop()
{
   // read the pushbutton input pin:
   buttonState = digitalRead(buttonPin);
   // compare the buttonState to its previous state
   if (buttonState != lastButtonState)
   {
      if (buttonState == LOW)
      {
         // if the current state is LOW then the button
         // went from off to on:         
         digitalWrite(ledPin, !digitalRead(ledPin)); // toggle the output
      }
      delay(20);
   }
   // save the current state as the last state,
   //for next time through the loop
   lastButtonState = buttonState;
}

Do you have a 10k pulldown resistor from pin 2 to GND? If not the pin is "floating" and could cause false HIGHs.