Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

Playing Audio Using Keystrokes: Is It Possible?

Annabelle5893

Gold Coder
I'm wondering, how would I make an app that plays audio files using the keys on the number pad? Specifically, I want to make an app that triggers "Rotary Pulse 1" by pressing 1 on the numeric keypad, all the way up to "Rotary Pulse 0" on the 0 key. A dial tone will be toggled on by pressing the spacebar, which will begin with a "receiver pickup" noise. The dial tone turns off when digits are dialed via the numeric keypad. If you press the spacebar either when the dial tone is on, or after dialing a number, a "Receiver Hang Up" noise will be triggered. With the rotary dial sounds, the dial turning to the fingerhole is triggered at key down, and the release of the dial returning to the resting position will be triggered by releasing of the number corresponding to the fingerhole (1, 2, 3, 4, 5, 6, 7, 8, 9, 0). This will be accompanied by the internal sound of the dial pulses as heard in a telephone. What is the code I would use to make this audio app using HTML?
 
Here's an error I've never experienced before. On Line 462:12, it says there's an "unlabeled break, must be in a loop or switch". Here's the code up to that point.
JavaScript:
        case "*57":
            var randNum57=Math.random()>=0.5;
            if(randNum57){
                var pickupCallTrace=new Audio('callResponses/trace3-xxx-fleet.mp3');
    } else {
                var pickupCallTrace=new Audio('callResponses/trace-xxx-fleet.mp3');
            }
            pickupCallTrace.addEventListener("ended", 
function() {timeoutHowler();
            pickupCallTrace.play();
            break;
 
Here's an error I've never experienced before. On Line 462:12, it says there's an "unlabeled break, must be in a loop or switch". Here's the code up to that point.
JavaScript:
        case "*57":
            var randNum57=Math.random()>=0.5;
            if(randNum57){
                var pickupCallTrace=new Audio('callResponses/trace3-xxx-fleet.mp3');
    } else {
                var pickupCallTrace=new Audio('callResponses/trace-xxx-fleet.mp3');
            }
            pickupCallTrace.addEventListener("ended",
function() {timeoutHowler();
            pickupCallTrace.play();
            break;
so here's a question for you:
is that break inside of that addEventListener callback function?

HINT HINT HINT
 
Here's an error I've never experienced before. On Line 462:12, it says there's an "unlabeled break, must be in a loop or switch". Here's the code up to that point.
JavaScript:
        case "*57":
            var randNum57=Math.random()>=0.5;
            if(randNum57){
                var pickupCallTrace=new Audio('callResponses/trace3-xxx-fleet.mp3');
    } else {
                var pickupCallTrace=new Audio('callResponses/trace-xxx-fleet.mp3');
            }
//HINT HINT HINT            pickupCallTrace.addEventListener("ended",
function() {timeoutHowler();
            pickupCallTrace.play();
            break;
This might help
 
How's this code?
JavaScript:
        case "*57":
            var randNum57=Math.random()>=0.5;
            if(randNum57){
                var pickupCallTrace=new Audio('callResponses/trace3-xxx-fleet.mp3');
    } else {
                var pickupCallTrace=new Audio('callResponses/trace-xxx-fleet.mp3');
           pickupCallTrace.addEventListener("ended",
function() {timeoutHowler();
            pickupCallTrace.play();
            break;
 
How's this code?
JavaScript:
        case "*57":
            var randNum57=Math.random()>=0.5;
            if(randNum57){
                var pickupCallTrace=new Audio('callResponses/trace3-xxx-fleet.mp3');
    } else {
                var pickupCallTrace=new Audio('callResponses/trace-xxx-fleet.mp3');
           pickupCallTrace.addEventListener("ended",
function() {timeoutHowler();
            pickupCallTrace.play();
            break;
I am not seeing the following:
1) closing bracket for that else statement
2) closing bracket for that function inside of event listener
3) closing parenthesis for that event listener call
 
I am not seeing the following:
1) closing bracket for that else statement
2) closing bracket for that function inside of event listener
3) closing parenthesis for that event listener call
1. Is this right?
Code:
    } else
2. How about this?
Code:
           pickupCallTrace.addEventListener("ended"),
3. Is this right?
Code:
function() {timeoutHowler();
}
 
1. Is this right?
Code:
    } else
2. How about this?
Code:
           pickupCallTrace.addEventListener("ended"),
3. Is this right?
Code:
function() {timeoutHowler();
}
nope.

JavaScript:
 if(randNum57){
    var pickupCallTrace=new Audio('callResponses/trace3-xxx-fleet.mp3');
 } else {
    var pickupCallTrace=new Audio('callResponses/trace-xxx-fleet.mp3');
    pickupCallTrace.addEventListener("ended", function() {
        timeoutHowler();
    //is that all for that event listener? If so, you are missing "}" to close out the function, and ")" to close out the call to the event listener
        pickupCallTrace.play();  //is this also part of that event listener?
    //where is the closing "}" for that else?
        break; //this should be the last line of your case statement.
I do honestly hope this clears things up.
 
Yes, pickupCallTrace.play(); is part of the EventListener. For some reason I thought there was supposed to be a } at the beginning of the "else" line. Is it supposed to go at the end instead?
When using an if statement, there should be one pair of "( )" and one pair of "{ }"
JavaScript:
if ( true ) [B]{[/B]
    //logic here
[B]}[/B]

When using an if-else statement there should be 1 pair of "( )" and 2 pairs of "{ }", one for the if statement, and one for the else statement... For lack of better words, the "else" keyword should be "sandwiched" between the CLOSING BRACKET FOR THE BODY OF THE IF STATEMENT and THE OPENING BRACKET FOR else-logic... see below
JavaScript:
if ( true ) [B]{[/B]
    //logic here
[B]}[/B] else {
    //logic here
}

HINT: count the number of pairs
However, my comment still stands... you are missing that close bracket "}" at the end of your else-logic
 
When using an if statement, there should be one pair of "( )" and one pair of "{ }"
JavaScript:
if ( true ) [B]{[/B]
    //logic here
[B]}[/B]

When using an if-else statement there should be 1 pair of "( )" and 2 pairs of "{ }", one for the if statement, and one for the else statement... For lack of better words, the "else" keyword should be "sandwiched" between the CLOSING BRACKET FOR THE BODY OF THE IF STATEMENT and THE OPENING BRACKET FOR else-logic... see below
JavaScript:
if ( true ) [B]{[/B]
    //logic here
[B]}[/B] else {
    //logic here
}

HINT: count the number of pairs
However, my comment still stands... you are missing that close bracket "}" at the end of your else-logic
I bolded the opening and closing brackets for the if statements to help you tell the difference
 
Yes, pickupCallTrace.play(); is part of the EventListener. Where should I move that line to? Should it be between the
pickupCallTrace.addEventListener("ended"),and the
function() {timeoutHowler();
lines?
if it's part of the event listener, then it should be inside of that function... between the { and the } of the function that is inside of the event listener
 
if it's part of the event listener, then it should be inside of that function... between the { and the } of the function that is inside of the event listener
How's this? I hope it looks right to you.
Code:
        case "*57":
            var randNum57=Math.random()>=0.5;
            if(randNum57) {
                var pickupCallTrace=new Audio('callResponses/trace3-xxx-fleet.mp3');
}
else {
                var pickupCallTrace=new Audio('callResponses/trace-xxx-fleet.mp3');
           pickupCallTrace.addEventListener("ended"),
function() {timeoutHowler();
            pickupCallTrace.play();
}
            break;
 
How's this? I hope it looks right to you.
Code:
        case "*57":
            var randNum57=Math.random()>=0.5;
            if(randNum57) {
                var pickupCallTrace=new Audio('callResponses/trace3-xxx-fleet.mp3');
}
else {
                var pickupCallTrace=new Audio('callResponses/trace-xxx-fleet.mp3');
           pickupCallTrace.addEventListener("ended"),
function() {timeoutHowler();
            pickupCallTrace.play();
}
            break;
you're still missing a closing " ) " for the event listener.. and the closing "}" right it to close out the else statement... again, please pay close attention to number of opening/closing brackets and parenthesis and their locations
 
you're still missing a closing " ) " for the event listener.. and the closing "}" right it to close out the else statement... again, please pay close attention to number of opening/closing brackets and parenthesis and their locations
Should there not be a comma after the ) of pickupCallTrace.addEventListener("ended")? Maybe that's what was wrong.
 
Should there not be a comma after the ) of pickupCallTrace.addEventListener("ended")? Maybe that's what was wrong.


your code
JavaScript:
        case "*57":
            var randNum57=Math.random()>=0.5;
            if(randNum57) {
                var pickupCallTrace=new Audio('callResponses/trace3-xxx-fleet.mp3');
}
else {
                var pickupCallTrace=new Audio('callResponses/trace-xxx-fleet.mp3');
           pickupCallTrace.addEventListener("ended"),
function() {timeoutHowler();
            pickupCallTrace.play();
}
            break;


Corrected code
JavaScript:
        case "*57":
            var randNum57=Math.random()>=0.5;
            if(randNum57) {
                var pickupCallTrace=new Audio('callResponses/trace3-xxx-fleet.mp3');
            } else {
                var pickupCallTrace=new Audio('callResponses/trace-xxx-fleet.mp3');
                pickupCallTrace.addEventListener("ended", function() {
                    timeoutHowler();
                    pickupCallTrace.play();
                });
            }
            break;


Please take a look at your code, and the corrected way below... notice where your mistakes were
 
I corrected a few more pieces of code with your fixes. Here's what I have.
Code:
<script>
var dialTone=new Audio('file:///M:/Documents/Virtual%20Phone/Call%20Progress%20Tones/Dial%20Tone/USA%20Dial%20Tone.ogg');
var isOffHook=false;
var callIncoming=false;
var allowDial = true;
var ringingTone=new Audio('Ringing Tone/Princess%20702B%20Bell%20Ring.ogg');
var timesRung=0;
var availableNumbers=["0","611","711","811","911","*67 + 1 (847) 765-1008","1 (847) 765-1008","867-5309",
                        "1 (212) 456-1414","555-1212","555-5555","748-0900","650-0050","650-8950",
                        "970-3920","1 (714) 733-9969","*57","*69"];


function reload(){
    location.reload(true);
}

document.getElementById('toggleLineStatus').onclick=function(){toggleLineStatus()};
function toggleLineStatus()
{
    var number="";
    var pin="";
    var checkForPin=false;
    document.getElementById('numberbeingdialed').innerHTML=number;
    var wasOnHook=false;
   
    if(!offHook){
        offHook=true;
        document.getElementById('hookstatus').innerHTML="Off";
        wasOnHook=true;
    } else {
        offHook=false;
        document.getElementById('hookstatus').innerHTML="On";
        clunk.pause();
        ringback.pause();
        clunk.currentTime=0;
        ringback.currentTime=0;
    }

    if(ringbackDialed){
        startRingback();
    } else {
        if(wasOnHook){
            ring.pause();
            ring.currentTime=0;
            playDialTone();
            dialingAllowed=true;
            nextDigitDialable=true;
            ringbackDialed=false;
            keepPlaying=true;
        } else {
            stopDialTone();
            setOpacity(100);
            allCircuitsBusy=false;
            keepPlaying=false;
        }
    }
}

function numberSuggestion(){
    var randomNumber=Math.floor(Math.random()*(availableNumbers.length));
    var suggestedNumber=availableNumbers[randomNumber];
    document.getElementById("suggestion").innerHTML="How about dialing <strong id='suggestedTelephoneNumber'>"+
                                                    suggestedNumber+
                                                    "</strong>? Don't like this number? Click the button above again!";
}

function receiverRaised(){
    if(allowDial == false) {
        telephoneAnswered()
}
    if(allowDial == true) {
        dialTone.play();
    } else
offHook ();
timeoutHowler.play();

}
setCallTimeout();
function setCallTimeout(){
    var delay=5000;
    var delayCaller=Math.floor((Math.random()*8000)+1);
    delay=delay+delayCaller;
    setTimeout(incomingCall,delay);
}

function offHook(){isOffHook=true;
document.getElementById("WE2500").style.display="none";
document.getElementById("dialPad").style.display="block";
}

function dialToneTimedOut() {
allowDial=false;
timeoutHowler();
    if(DialToneTimedOut == true) {
        timeoutHowler.play();
        timeoutHowler.currentTime=0;
}

function incomingCall(){
    
    var ringRing=new Audio('Ringing Tone/Princess%20702B%20Bell%20Ring.ogg');
    var hasTelephoneBeenAnswered=false;
    ringTelephone();
}

function ringTelephone(){ 
    if(!hasTelephoneBeenAnswered == false) {
        ringRing.play();
        ringRing.currentTime=0;
    }
    
    if(isOffHook == false) {
        ringRing.play();
    }
    if(allowDial == false) {
    callIncoming=true;
    setInterval(ringTelephone,5500);
}

var number="";var timeout;
function numberDial() {
if(dialTone){dialTone.pause();
dialTone.currentTime=0
}

function dial1() {
    if(allowDial == true) {
        numberDial();
        number=number+"1";
        var DTMFToneDial1=new Audio('file:///M:/Documents/Virtual%20Phone/DTMF%20Tone%20Dials/DTMF%20Tone%20Dial%201.ogg');
        DTMFToneDial1.play();
}
function dial2() {
    if(allowDial == true); {
        numberDial();
        number=number+"2";
        var DTMFToneDial2=new Audio('file:///M:/Documents/Virtual%20Phone/DTMF%20Tone%20Dials/DTMF%20Tone%20Dial%202.ogg');
        DTMFToneDial2.play();
}

function dial3() {
    if(allowDial == true); {
        numberDial();
        number=number+"3";
        var DTMFToneDial3=new Audio('file:///M:/Documents/Virtual%20Phone/DTMF%20Tone%20Dials/DTMF Tone Dial 3.ogg');
        DTMFToneDial3.play();
}

function dial4() {
    if(allowDial == true) {
        numberDial();
        number=number+"4";
        var DTMFToneDial4=new Audio('file:///M:/Documents/Virtual%20Phone/DTMF%20Tone%20Dials/DTMF Tone Dial 4.ogg');
        DTMFToneDial4.play();
}

function dial5() {
    if(allowDial == true) {
        numberDial();
        number=number+"5";
        var DTMFToneDial5=new Audio('file:///M:/Documents/Virtual%20Phone/DTMF%20Tone%20Dials/DTMF Tone Dial 5.ogg');
        DTMFToneDial5.play();
}

function dial6() {
    if(allowDial == true) {
        numberDial();
        number=number+"6";
        var DTMFToneDial6=new Audio('file:///M:/Documents/Virtual%20Phone/DTMF%20Tone%20Dials/DTMF Tone Dial 6.ogg');
        DTMFToneDial6.play();
}

function dial7() {
    if(allowDial == true) {
    numberDial();
    number=number+"7";
    var DTMFToneDial7=new Audio('file:///M:/Documents/Virtual%20Phone/DTMF%20Tone%20Dials/DTMF Tone Dial 7.ogg');
    DTMFToneDial7.play();
}

function dial8() {
    if(allowDial == true) {
        numberDial();
        number=number+"8";
        var DTMFToneDial8=new Audio('file:///M:/Documents/Virtual%20Phone/DTMF%20Tone%20Dials/DTMF Tone Dial 8.ogg');
        DTMFToneDial8.play();
}

function dial9() {
    if(allowDial == true) {
        numberDial();
        number=number+"9";
        var DTMFToneDial9=new Audio('file:///M:/Documents/Virtual%20Phone/DTMF%20Tone%20Dials/DTMF Tone Dial 9.ogg');
        DTMFToneDial9.play();
}

function dialStar() {
    if(allowDial == true) {
        numberDial();
        number=number+"*";
        var DTMFToneDialStar=new Audio('file:///M:/Documents/Virtual%20Phone/DTMF%20Tone%20Dials/DTMF Tone Dial Star.ogg');
        DTMFToneDialStar.play();
}

function dial0() {
    if(allowDial == true) {
        numberDial();
        number=number+"0";
        var DTMFToneDial0=new Audio('file:///M:/Documents/Virtual%20Phone/DTMF%20Tone%20Dials/DTMF Tone Dial 0.ogg');
        DTMFToneDial0.play();
    }

function dialPound(){
    if(allowDial == true) {
        numberDial();
        number=number+"#";
        var DTMFToneDialPound=new Audio('file:///M:/Documents/Virtual%20Phone/DTMF%20Tone%20Dials/DTMF Tone Dial Pound.ogg');
        DTMFToneDialPound.play();
}

document.onkeydown = function (event) {
switch (event.keycode) {
    case 32:
        toggleLineStatus();
        break;
    case 49,97:
        dial1();
        break;
    case 50,98:
        dial2();
        break;
    case 51,99:
        dial3();
        break;
    case 52,100:
        dial4();
        break;
    case 53,101:
        dial5();
        break;
    case 54,102:
        dial6();
        break;
    case 55,103:
        dial7();
        break;
    case 56,104:
        dial8();
        break;
    case 57,105:
        dial9();
        break;
    case 106:
        dialStar();
        break;
    case 48,96:
        dial0();
        break;
    case 109:
        dialPound();
        break;
    default:
        hasDialedNumber = false;
}
function ring(){
    ringingTone.play();
    timesRung++;
    if(timesRung>1) {
        setTimeout(response,700);
    }    

function dial(){
    allowDial=false;
    ring(); 
    setTimeout(ring,4000);
}

function busy() {
busyTone();
function busyTone() {
var pickupBusy=new Audio('file:///M:/Documents/Virtual%20Phone/Call%20Progress%20Tones/Busy%20Tone/USA%20Busy%20Tone.ogg');
pickupBusy.play();
pickupBusy.currentTime=0;
}
setInterval(busyTone,4000);
}

function response(){
    switch(number){
        case "0":
            var operatorPickup=new Audio('callResponses/OperatorAnswer.wav');
            operatorPickup.addEventListener("ended"),
function(){number=prompt("Operator, your number please? (Numbers only; enter 'police' for police and emergency)");
                if(number==null){
                    number="0";
                }
                operatorPutCallThrough();
            });
            operatorPickup.play();
                });
            }
            break;
        case "611":
            var pickup611=new Audio('callResponses/611.wav');
            pickup611.addEventListener("ended", function(){
                timeoutHowler();
            });
            pickup611.play();
                });
            }
            break;
        case "711":
            var pickup711=new Audio('callResponses/tdd-1.mp3');
            pickup711.play();
                });
            }
            break;
        case "811":
            var pickup611=new Audio('callResponses/811.wav');
            pickup811.addEventListener("ended", function() {
                timeoutHowler();
            pickup811.play();
                });
            }
            break;
        case "911":
            var pickup911=new Audio('callResponses/911-xxx-fleet.mp3');
            pickup911.addEventListener("ended", function() {
                timeoutHowler();
            pickup911.play();
                });
            }
            break;
        case "18477651008":
            var pickupMCI=new Audio('callResponses/MCI.wav');
            pickupMCI.play();
                });
            }
            break;
        case "8675309":
            var pickup8675309=new Audio('callResponses/discoornis-bell-f1.mp3');
            pickup8675309.addEventListener("ended",    function(){
                timeoutHowler();
            });
            pickup8675309.play();
                });
            }
            break;
        case "12124561414":
            busy();
            break;
        case "5551212":
            busy();
            break;
        case "5555555":
            var pickup5555555=new Audio('callResponses/timeout-xxx-fleet.mp3');
            pickup5555555.addEventListener("ended",
                function(){timeoutHowler();
            pickup5555555.play();
                });
            }
            break;
        case "7480900":
            var pickupSelf=new Audio('callResponses/partyline-xxx-fleet.mp3');
            pickupSelf.play();
            break;
        case "18005820655":
            busy();
            break;
        case "6508950":
            var pickupAM=new Audio('callResponses/answering-machine-1.mp3');
            pickupAM.play();
            break;
        case "6500050":
            var pickupModem=new Audio('modem.wav');
            pickupModem.play();
            break;
        case "9703920":
            var pickupFax=new Audio('fax-1.mp3');
            pickupFax.play();
            break;
        case "17147339969":
            var pickup714=new Audio('device-conference.mp3');
            pickup714.play();
                });
            }
            break;
        case "*8217147339969":
            var pickup714=new Audio('device-conference.mp3');
            pickup714.play();
                });
            }
            break;
        case "*6717147339969":
            var pickup714block=new Audio('callResponses/reject2-xxx-fleet.mp3');
            pickup714block.addEventListener("ended",
function() {
                timeoutHowler();
            pickup714block.play();
                });
            }
            break;
        case "*57":
            var randNum57=Math.random()>=0.5;
            if(randNum57) {
                var pickupCallTrace=new Audio('callResponses/trace3-xxx-fleet.mp3');
            } else {
                var pickupCallTrace=new Audio('callResponses/trace-xxx-fleet.mp3');
                pickupCallTrace.addEventListener("ended", function() {
                    timeoutHowler();
                    pickupCallTrace.play();
                });
            }
            break;
        case "*69":
            var pickupStar69=new Audio('callResponses/return-xxx-fleet.mp3');
            pickupStar69.addEventListener("ended",
function() {timeoutHowler();
            pickupStar69.play();
                });
            }
            break;
        case "police":
            var pickupPolice=new Audio('callResponses/policePickup.wav');
            pickupPolice.addEventListener("ended",
function() {timeoutHowler();
                var policeComplaint=prompt("Police Department, Sergeant Duffy Speaking.");
                confirm("Really? You say that "+policeComplaint);
                var policeHangup=new Audio('callResponses/policeHangup.wav');
                policeHangup.addEventListener("ended", 
function() {timeoutHowler();
}
            pickupPolice.play();
                });
            }
            break;
        default:
            var pickupDefault;
            if(number.length>7){
                pickupDefault=new Audio('callResponses/ldcircuits-bell-f1.mp3');
    } else {
                pickupDefault=new Audio('callResponses/completeordc-xxx-fleet.mp3');
            }
            pickupDefault.addEventListener("ended", function() { 
                timeoutHowler();
            });
            pickupDefault.play();
            break;
    }
</script>
 
I corrected a few more pieces of code with your fixes. Here's what I have.
Code:
<script>
var dialTone=new Audio('file:///M:/Documents/Virtual%20Phone/Call%20Progress%20Tones/Dial%20Tone/USA%20Dial%20Tone.ogg');
var isOffHook=false;
var callIncoming=false;
var allowDial = true;
var ringingTone=new Audio('Ringing Tone/Princess%20702B%20Bell%20Ring.ogg');
var timesRung=0;
var availableNumbers=["0","611","711","811","911","*67 + 1 (847) 765-1008","1 (847) 765-1008","867-5309",
                        "1 (212) 456-1414","555-1212","555-5555","748-0900","650-0050","650-8950",
                        "970-3920","1 (714) 733-9969","*57","*69"];


function reload(){
    location.reload(true);
}

document.getElementById('toggleLineStatus').onclick=function(){toggleLineStatus()};
function toggleLineStatus()
{
    var number="";
    var pin="";
    var checkForPin=false;
    document.getElementById('numberbeingdialed').innerHTML=number;
    var wasOnHook=false;
 
    if(!offHook){
        offHook=true;
        document.getElementById('hookstatus').innerHTML="Off";
        wasOnHook=true;
    } else {
        offHook=false;
        document.getElementById('hookstatus').innerHTML="On";
        clunk.pause();
        ringback.pause();
        clunk.currentTime=0;
        ringback.currentTime=0;
    }

    if(ringbackDialed){
        startRingback();
    } else {
        if(wasOnHook){
            ring.pause();
            ring.currentTime=0;
            playDialTone();
            dialingAllowed=true;
            nextDigitDialable=true;
            ringbackDialed=false;
            keepPlaying=true;
        } else {
            stopDialTone();
            setOpacity(100);
            allCircuitsBusy=false;
            keepPlaying=false;
        }
    }
}

function numberSuggestion(){
    var randomNumber=Math.floor(Math.random()*(availableNumbers.length));
    var suggestedNumber=availableNumbers[randomNumber];
    document.getElementById("suggestion").innerHTML="How about dialing <strong id='suggestedTelephoneNumber'>"+
                                                    suggestedNumber+
                                                    "</strong>? Don't like this number? Click the button above again!";
}

function receiverRaised(){
    if(allowDial == false) {
        telephoneAnswered()
}
    if(allowDial == true) {
        dialTone.play();
    } else
offHook ();
timeoutHowler.play();

}
setCallTimeout();
function setCallTimeout(){
    var delay=5000;
    var delayCaller=Math.floor((Math.random()*8000)+1);
    delay=delay+delayCaller;
    setTimeout(incomingCall,delay);
}

function offHook(){isOffHook=true;
document.getElementById("WE2500").style.display="none";
document.getElementById("dialPad").style.display="block";
}

function dialToneTimedOut() {
allowDial=false;
timeoutHowler();
    if(DialToneTimedOut == true) {
        timeoutHowler.play();
        timeoutHowler.currentTime=0;
}

function incomingCall(){
 
    var ringRing=new Audio('Ringing Tone/Princess%20702B%20Bell%20Ring.ogg');
    var hasTelephoneBeenAnswered=false;
    ringTelephone();
}

function ringTelephone(){
    if(!hasTelephoneBeenAnswered == false) {
        ringRing.play();
        ringRing.currentTime=0;
    }
 
    if(isOffHook == false) {
        ringRing.play();
    }
    if(allowDial == false) {
    callIncoming=true;
    setInterval(ringTelephone,5500);
}

var number="";var timeout;
function numberDial() {
if(dialTone){dialTone.pause();
dialTone.currentTime=0
}

function dial1() {
    if(allowDial == true) {
        numberDial();
        number=number+"1";
        var DTMFToneDial1=new Audio('file:///M:/Documents/Virtual%20Phone/DTMF%20Tone%20Dials/DTMF%20Tone%20Dial%201.ogg');
        DTMFToneDial1.play();
}
function dial2() {
    if(allowDial == true); {
        numberDial();
        number=number+"2";
        var DTMFToneDial2=new Audio('file:///M:/Documents/Virtual%20Phone/DTMF%20Tone%20Dials/DTMF%20Tone%20Dial%202.ogg');
        DTMFToneDial2.play();
}

function dial3() {
    if(allowDial == true); {
        numberDial();
        number=number+"3";
        var DTMFToneDial3=new Audio('file:///M:/Documents/Virtual%20Phone/DTMF%20Tone%20Dials/DTMF Tone Dial 3.ogg');
        DTMFToneDial3.play();
}

function dial4() {
    if(allowDial == true) {
        numberDial();
        number=number+"4";
        var DTMFToneDial4=new Audio('file:///M:/Documents/Virtual%20Phone/DTMF%20Tone%20Dials/DTMF Tone Dial 4.ogg');
        DTMFToneDial4.play();
}

function dial5() {
    if(allowDial == true) {
        numberDial();
        number=number+"5";
        var DTMFToneDial5=new Audio('file:///M:/Documents/Virtual%20Phone/DTMF%20Tone%20Dials/DTMF Tone Dial 5.ogg');
        DTMFToneDial5.play();
}

function dial6() {
    if(allowDial == true) {
        numberDial();
        number=number+"6";
        var DTMFToneDial6=new Audio('file:///M:/Documents/Virtual%20Phone/DTMF%20Tone%20Dials/DTMF Tone Dial 6.ogg');
        DTMFToneDial6.play();
}

function dial7() {
    if(allowDial == true) {
    numberDial();
    number=number+"7";
    var DTMFToneDial7=new Audio('file:///M:/Documents/Virtual%20Phone/DTMF%20Tone%20Dials/DTMF Tone Dial 7.ogg');
    DTMFToneDial7.play();
}

function dial8() {
    if(allowDial == true) {
        numberDial();
        number=number+"8";
        var DTMFToneDial8=new Audio('file:///M:/Documents/Virtual%20Phone/DTMF%20Tone%20Dials/DTMF Tone Dial 8.ogg');
        DTMFToneDial8.play();
}

function dial9() {
    if(allowDial == true) {
        numberDial();
        number=number+"9";
        var DTMFToneDial9=new Audio('file:///M:/Documents/Virtual%20Phone/DTMF%20Tone%20Dials/DTMF Tone Dial 9.ogg');
        DTMFToneDial9.play();
}

function dialStar() {
    if(allowDial == true) {
        numberDial();
        number=number+"*";
        var DTMFToneDialStar=new Audio('file:///M:/Documents/Virtual%20Phone/DTMF%20Tone%20Dials/DTMF Tone Dial Star.ogg');
        DTMFToneDialStar.play();
}

function dial0() {
    if(allowDial == true) {
        numberDial();
        number=number+"0";
        var DTMFToneDial0=new Audio('file:///M:/Documents/Virtual%20Phone/DTMF%20Tone%20Dials/DTMF Tone Dial 0.ogg');
        DTMFToneDial0.play();
    }

function dialPound(){
    if(allowDial == true) {
        numberDial();
        number=number+"#";
        var DTMFToneDialPound=new Audio('file:///M:/Documents/Virtual%20Phone/DTMF%20Tone%20Dials/DTMF Tone Dial Pound.ogg');
        DTMFToneDialPound.play();
}

document.onkeydown = function (event) {
switch (event.keycode) {
    case 32:
        toggleLineStatus();
        break;
    case 49,97:
        dial1();
        break;
    case 50,98:
        dial2();
        break;
    case 51,99:
        dial3();
        break;
    case 52,100:
        dial4();
        break;
    case 53,101:
        dial5();
        break;
    case 54,102:
        dial6();
        break;
    case 55,103:
        dial7();
        break;
    case 56,104:
        dial8();
        break;
    case 57,105:
        dial9();
        break;
    case 106:
        dialStar();
        break;
    case 48,96:
        dial0();
        break;
    case 109:
        dialPound();
        break;
    default:
        hasDialedNumber = false;
}
function ring(){
    ringingTone.play();
    timesRung++;
    if(timesRung>1) {
        setTimeout(response,700);
    } 

function dial(){
    allowDial=false;
    ring();
    setTimeout(ring,4000);
}

function busy() {
busyTone();
function busyTone() {
var pickupBusy=new Audio('file:///M:/Documents/Virtual%20Phone/Call%20Progress%20Tones/Busy%20Tone/USA%20Busy%20Tone.ogg');
pickupBusy.play();
pickupBusy.currentTime=0;
}
setInterval(busyTone,4000);
}

function response(){
    switch(number){
        case "0":
            var operatorPickup=new Audio('callResponses/OperatorAnswer.wav');
            operatorPickup.addEventListener("ended"),
function(){number=prompt("Operator, your number please? (Numbers only; enter 'police' for police and emergency)");
                if(number==null){
                    number="0";
                }
                operatorPutCallThrough();
            });
            operatorPickup.play();
                });
            }
            break;
        case "611":
            var pickup611=new Audio('callResponses/611.wav');
            pickup611.addEventListener("ended", function(){
                timeoutHowler();
            });
            pickup611.play();
                });
            }
            break;
        case "711":
            var pickup711=new Audio('callResponses/tdd-1.mp3');
            pickup711.play();
                });
            }
            break;
        case "811":
            var pickup611=new Audio('callResponses/811.wav');
            pickup811.addEventListener("ended", function() {
                timeoutHowler();
            pickup811.play();
                });
            }
            break;
        case "911":
            var pickup911=new Audio('callResponses/911-xxx-fleet.mp3');
            pickup911.addEventListener("ended", function() {
                timeoutHowler();
            pickup911.play();
                });
            }
            break;
        case "18477651008":
            var pickupMCI=new Audio('callResponses/MCI.wav');
            pickupMCI.play();
                });
            }
            break;
        case "8675309":
            var pickup8675309=new Audio('callResponses/discoornis-bell-f1.mp3');
            pickup8675309.addEventListener("ended",    function(){
                timeoutHowler();
            });
            pickup8675309.play();
                });
            }
            break;
        case "12124561414":
            busy();
            break;
        case "5551212":
            busy();
            break;
        case "5555555":
            var pickup5555555=new Audio('callResponses/timeout-xxx-fleet.mp3');
            pickup5555555.addEventListener("ended",
                function(){timeoutHowler();
            pickup5555555.play();
                });
            }
            break;
        case "7480900":
            var pickupSelf=new Audio('callResponses/partyline-xxx-fleet.mp3');
            pickupSelf.play();
            break;
        case "18005820655":
            busy();
            break;
        case "6508950":
            var pickupAM=new Audio('callResponses/answering-machine-1.mp3');
            pickupAM.play();
            break;
        case "6500050":
            var pickupModem=new Audio('modem.wav');
            pickupModem.play();
            break;
        case "9703920":
            var pickupFax=new Audio('fax-1.mp3');
            pickupFax.play();
            break;
        case "17147339969":
            var pickup714=new Audio('device-conference.mp3');
            pickup714.play();
                });
            }
            break;
        case "*8217147339969":
            var pickup714=new Audio('device-conference.mp3');
            pickup714.play();
                });
            }
            break;
        case "*6717147339969":
            var pickup714block=new Audio('callResponses/reject2-xxx-fleet.mp3');
            pickup714block.addEventListener("ended",
function() {
                timeoutHowler();
            pickup714block.play();
                });
            }
            break;
        case "*57":
            var randNum57=Math.random()>=0.5;
            if(randNum57) {
                var pickupCallTrace=new Audio('callResponses/trace3-xxx-fleet.mp3');
            } else {
                var pickupCallTrace=new Audio('callResponses/trace-xxx-fleet.mp3');
                pickupCallTrace.addEventListener("ended", function() {
                    timeoutHowler();
                    pickupCallTrace.play();
                });
            }
            break;
        case "*69":
            var pickupStar69=new Audio('callResponses/return-xxx-fleet.mp3');
            pickupStar69.addEventListener("ended",
function() {timeoutHowler();
            pickupStar69.play();
                });
            }
            break;
        case "police":
            var pickupPolice=new Audio('callResponses/policePickup.wav');
            pickupPolice.addEventListener("ended",
function() {timeoutHowler();
                var policeComplaint=prompt("Police Department, Sergeant Duffy Speaking.");
                confirm("Really? You say that "+policeComplaint);
                var policeHangup=new Audio('callResponses/policeHangup.wav');
                policeHangup.addEventListener("ended",
function() {timeoutHowler();
}
            pickupPolice.play();
                });
            }
            break;
        default:
            var pickupDefault;
            if(number.length>7){
                pickupDefault=new Audio('callResponses/ldcircuits-bell-f1.mp3');
    } else {
                pickupDefault=new Audio('callResponses/completeordc-xxx-fleet.mp3');
            }
            pickupDefault.addEventListener("ended", function() {
                timeoutHowler();
            });
            pickupDefault.play();
            break;
    }
</script>
From just a quick glance, you are still missing quite a few closing brackets "}"... Please go through each function and count all the opening brackets "{" and all the closing brackets "}"... there should be the same amount of closing brackets as there are opening brackets. I do also still see a few else keywords without their brackets as well. It will help you out immensely if you also properly indent everything to line it up. I know it's a bit tricky to get the alignment correct when using bbcodes, but anything within a pair of opening brackets "{" and closing brackets "{" should be indented at least three spaces over. I typically do four spaces, but some editors and IDEs will use three for js by default.
 
Last edited:
Back
Top Bottom