Input Component Help

This forum contains topics that were moved from Get Satisfaction
William Chau
Posts: 0
Joined: Wed Oct 22, 2014 3:27 pm

Input Component Help

Post by William Chau »

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.]

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Input Component Help

Post by Kateryna Grynko »

Hi William,

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

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

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

var result = test1();
Apperyio('answer1').text( result );/pre

Post Reply