Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

My Solution to Context Menu

154 views
Skip to first unread message

Monique B

unread,
Jul 5, 2020, 8:10:30 AM7/5/20
to Intro to JavaScript
var tux = document.getElementById('tux');
var menu = document.getElementById('menu');
var photo = document.getElementById('option1');
var rub = document.getElementById('option2');
var feed = document.getElementById('option3');
var photoCount = 0;
var rubCount = 0;
var feedCount = 0;
var totalCount = 0;

var visible = function(e){
menu.style.display = 'block';
  menu.style.left = e.pageX + "px";
  menu.style.top = e.pageY + "px";
    e.preventDefault();
}

var hide = function(){
menu.style.display = 'none';
}

var tired = function(){
alert("Tux is tired of you now. Please leave him alone.");
}

var photoFunc = function(){
if(totalCount > 5){
    tired();
    } else if (photoCount < 1){
    alert("Tux is smiling for the camera!");
    } else {  
  alert("Tux does not want to take more photographs right now...");
    }
  
  photoCount++;
  totalCount++;
}

var rubFunc = function(){
  if(totalCount > 5){
    tired();
    } else if (rubCount == 1){
    alert("Tux is already satisfied with his belly rubs!");
    } else if (rubCount > 1){
    alert("Tux wants you to stop now please...");
    } else {
alert("Tux loves a good belly rub!");
    }
  
  rubCount++;
  totalCount++;
}

var feedFunc = function(){
  if(totalCount > 5){
    tired();
    } else if (feedCount == 1){
    alert("Tux is already full.");
    } else if (feedCount > 1){
    alert("Tux wants you to stop now please...");
    } else {
alert("Tux enjoyed his fish! Thank you!");
    }
   
  feedCount++;
  totalCount++;
}

tux.addEventListener('contextmenu', visible, false);
document.addEventListener('click', hide, false);
photo.addEventListener('click', photoFunc, false);
rub.addEventListener('click', rubFunc, false);
feed.addEventListener('click', feedFunc, false);

Reply all
Reply to author
Forward
0 new messages