0

I am trying to check whether the content that a user has submitted contains the correct information. I am doing this by adding the inputted context to a variable [code] and then trying an if else catch to see whether it matches what I want. [strong] variable.

However, it does not appear to be working, can anyone shed some light on this? Please see the below code.

$(document).ready(function() {

    $('#button-bold').click(function() {  
        var code = jQuery("textarea#bold-code").val();

        var $pass = "Congratulations, You have entered this correctly";
        var $fail = "Oops, Look again, can you see where you have gone wrong?"

        var $strong = "<strong>Recreate this preview Exactly</strong>"; 

        if (code == strong) {
            alert(pass);
            $('#bold-output').append(code)

        }else {
            alert(fail);
        }
});
});

Thank you all in advance.

3
  • 6
    You've got $strong in one place and strong in the other? Ditto $pass and $fail. Commented May 21, 2013 at 15:40
  • Thank you very much, I tried adding the $ to them all at first but still missed the fact that [code] didnt have one so it didnt work. Thank you again :) How do I +1 your comment? Commented May 21, 2013 at 15:46
  • You don't have enough reputation to upvote a comment (it wouldn't do much beyond tell other people "yeah this is a helpful comment" anyway). If @Rup posted his comment as an answer, however, you'd be able to accept that as the solution. Commented May 21, 2013 at 16:00

1 Answer 1

1

You've got mismatched variable names with and without dollars - you're defining $strong, $pass and $fail with leading dollars but using strong, pass and fail without the dollar.

(As an aside, where you see the dollar prefix on JavaScript variables it usually means that they contain jQuery selectors, e.g.

var $output = $('#bold-output');

rather than general data - but that's just one convention.)

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.