Input Component Help

Hi,
I am trying to create a page where the users try and solve problem sums and input the answer in a text box. I have thus, created a button that shows whether the answer is correct or wrong in an input box by using this script when the button is pressed:

var a1 = Apperyio('M1').val();
var test1 = function()
{
if(a1 === 144)
{
return('correct');
}
else
{
return('Wrong');
}
};

var getvalue1 = Apperyio('answer1').text;

getvalue1(test1);

But this does not work, can someone help me?
[Sorry, I am not very good at coding.]
1 person has
this question
+1
This topic is no longer open for comments or replies.
  • Hi William,

    a1 stores a string variable so it's better to use == instead of === in your if condition:
    if(a1 == 144)


    As we can see, you want to use a result of function test1() in some element, to do it use this code:
    var result = test1();
    Apperyio('answer1').text( result );


    So all your code should be like this:
    var a1 = Apperyio('M1').val();
    var test1 = function()
    {
    if(a1 == 144)
    {
    return('correct');
    }
    else
    {
    return('Wrong');
    }
    };

    var result = test1();
    Apperyio('answer1').text( result );
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned kidding, amused, unsure, silly happy, confident, thankful, excited sad, anxious, confused, frustrated