1

I know there is so much topic with this subject but none of those topics solved my problem.

I have a javascript code and there is several function in it, after about an hour I finally found all function that is defined under a special function doesn't work and the error "ReferenceError: Can't find variable: functionName" will appear and all the other that is defined on top of that special function is work properly. My problem is that I can't find out what's wrong with this special function that causes this problem ... can anyone help me ?

Here is that special function :

function shift(btn) {
if (!shiftPressed) {
    document.getElementById("keyShift1").style.background = "rgb(180,50,0)";
    document.getElementById("keyShift2").style.background = "rgb(180,50,0)";
    for (var i = 65; i <= 90; i++) {
        var id = "key" + String.fromCharCode(i);
        document.getElementById(id).innerHTML = document.getElementById(id).value.toUpperCase();
    }
    document.getElementById("key~").innerHTML = "`";
    shiftPressed = !shiftPressed;

} else {
    document.getElementById("keyShift1").style.background = "black";
    document.getElementById("keyShift2").style.background = "black";

    document.getElementById("key~").innerHTML = "~";
    if (!capsPressed) {
        for (var i = 65; i <= 90; i++) {
            var id = "key" + String.fromCharCode(i);
            document.getElementById(id).innerHTML = document.getElementById(id).value.toLowerCase();
        }
    }
    shiftPressed = !shiftPressed;
}
2
  • Do you see any error in browser console? Commented Apr 15, 2016 at 10:26
  • yes ... for example if a function with name test() is defined under this function ... then i see this error : ReferenceError: Can't find variable: test Commented Apr 15, 2016 at 10:28

1 Answer 1

1

You have missed a curly brace at the end of the function

It should be

function shift(btn) {
    if (!shiftPressed) {
        document.getElementById("keyShift1").style.background = "rgb(180,50,0)";
        document.getElementById("keyShift2").style.background = "rgb(180,50,0)";

        for (var i = 65; i <= 90; i++) {
            var id = "key" + String.fromCharCode(i);
            document.getElementById(id).innerHTML = document.getElementById(id).value.toUpperCase();
        }

        document.getElementById("key~").innerHTML = "`";
        shiftPressed = !shiftPressed;
    } else {
        document.getElementById("keyShift1").style.background = "black";
        document.getElementById("keyShift2").style.background = "black";
        document.getElementById("key~").innerHTML = "~";

        if (!capsPressed) {
            for (var i = 65; i <= 90; i++) {
                var id = "key" + String.fromCharCode(i);
                document.getElementById(id).innerHTML = document.getElementById(id).value.toLowerCase();
            }
        }

        shiftPressed = !shiftPressed;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.