0

document.result.word.value works fine if it isn't a variable but as soon as i make it one it gives errors like "inputWord.charAt is not a function"

$(document).ready(function() {
$("#submit").click(function() {
    var amountOfLetters = 0;
    var inputWord = document.result.word.value.toLowerCase;
    for(i=0;i<5;i++) {
        var letter = inputWord.charAt(i);
        var counter = compWord.indexOf(letter);
        if(counter > -1) {
            amountOfLetters++;
        }
    }
    var isValidWord = 0;
    for(var i = 0; i < 8939; i++) {
        if(inputWord == library[i]) {
            isValidWord = 1;
            break;
        };
    };
    if(isValidWord == 0) {
        alert("You cannot use that word");
        $('#getWord').val('');
    } else {
        $(".left").append("<p id='list'>" + inputWord + "(" + amountOfLetters + ")" + "</p>");
        var compChoice = library[Math.floor((Math.random() * 8938) + 1)];
        $(".right").append("<p id='list'>" + compChoice + "</p>");
        $('#getWord').val('');
    };
});

});

1 Answer 1

1

toLowerCase is method, try to call it like this:

 var inputWord = document.result.word.value.toLowerCase();
Sign up to request clarification or add additional context in comments.

1 Comment

To be more specific, your original code was assigning to the inputWord variable a reference to the actual toLowerCase function that's built into every String object. Now you're trying to call the charAt() method on a function, not on a string - thus the error message you received.

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.