0
    <img id="corridor" src="Images/Corridor.jpg" class="centre" usemap="#map1">
            <img id = "key" src="Images/key.png" onclick="pickupKey()">
    
    <map name="map1">
        <area onclick="tryDoor()" id="door1" onblur="door1.focus()" autofocus shape="rect" coords="830,240,750,350"/>
    </map>



    function tryDoor(){
        if (hasKey == true) {
        alert("you open the door");
        }else{
        alert("The door is locked find a key");

how can i make it so that when hasKey == true and the door is opened the user will be taken to a different webpage. I have been unsuccessful in trying to use hyperlinks to solve this issue.

Thanks.

1 Answers1

0

I assume you have a separate var for doorIsOpen.

var doorIsOpen = false;

if (hasKey == true) {
    if(!doorIsOpen) {
        alert("you open the door");
        doorIsOpen = true;
    } else {
        document.location.href = "www.google.com";
    }
} else {
       alert('door is locked');
}
Ahmad
  • 12,336
  • 6
  • 48
  • 88