I am building a game in JavaScript along with html5. I want my front page to display a bit of text and then when I press any button suppose if `p` then the actual game starts.

I have used flag in this case to toggle between two functions one which brings the front page and another which is actually starting the game.
Here's my code:

```
var flag1 =true;
function init() 
 {
  canvas = document.getElementById('canvas');
  region = canvas.getContext('2d');
  if(flag1==true)
   {
    front();
   }
  else
   {
    start();
   }  
 }
function front()
 {
   document.write("press p to play");

   document.onkeydown = function(event) 
   {

     var keyCode; 
     if(event == null)
    {
     keyCode = window.event.keyCode; 
    }
    else 
    {
    keyCode = event.keyCode; 
    }

    switch(keyCode)
    {
       case 80:
       flag1=false;
       init();
       break;

       default: 
       break;

     }
 }
 }

 function start()
 {
  *************
   *********
  *********
 }

```

This code is giving an error in console whenever I press `p`, i.e.

> 
> init() is not defined
> 
> 
> 

Can anyone sort this problem?