Page 1 of 1

If statements in Java

Posted: Thu Mar 07, 2013 7:45 pm
by Matt Oakes

I'm setting a variable using an input field and a button. Once the button is pressed, I also want it to compare the input to a pre-defined value and to display a message in a label if these match (by, for example, making the label visible).

For example, a question is displayed. The user enters the answer and presses the button. The button assigns this to a variable. I need something that also says:

If variable = "James Bond" then make label visible.

How would I do this using Java in Tiggzi?

Thanks,

Matt


If statements in Java

Posted: Thu Mar 07, 2013 7:48 pm
by maxkatz

Tiggzi is a platform to build apps (http://docs.tiggzi.com/getting-started/) - the app that you create is a standard HTML/JavaScript/CSS app that runs in the browser. You can also build hybrid apps. To add any logic such as if-statement you would use JavaScript (there is no Java).


If statements in Java

Posted: Thu Mar 07, 2013 8:05 pm
by Matt Oakes

Sorry - I meant Javascript, as accessed through the "event" tab and "Run Javascript". I'm struggling to put together the "if" statement - it doesn't seem to work. Any advice for how to compare this variable in local storage to a set value and make a label visible if they match?

Thanks,

Matt


If statements in Java

Posted: Thu Mar 07, 2013 8:15 pm
by maxkatz

https://developer.mozilla.org/en-US/d...

To read data from local storage:
localStorage.getItem('name');


If statements in Java

Posted: Thu Mar 07, 2013 8:22 pm
by Matt Oakes

So, should this work for the first line?

if (localStorage.getItem('Answer') = 'James Bond')

Where Answer is the variable.

What, then, is the command for setting a label to visible?

Thanks,

Matt


If statements in Java

Posted: Thu Mar 07, 2013 10:01 pm
by maxkatz

If 'Answer' is stored in local storage, then yes. You also need to use ==

To set a label visible, select the component you need and then use .show()/hide() or .toggle(). These are all jQuery methods.


If statements in Java

Posted: Mon Mar 11, 2013 4:55 pm
by Matt Oakes

Sorry to be a pain, but I still can't get this to work. I've been looking at online tutorials for JavaScript without much luck.

Assuming that Answer is the local storage variable and the label which I want to unhide is called Output, what would the second line of code be? When "James Bond" is entered into the field and the button pressed, I would like it to unhide Output.

I assume that the first would be:

if (localStorage.getItem('Answer') = 'James Bond')

How is the unhiding of the Output label then done?

Thanks for any help you can give me!

Matt


If statements in Java

Posted: Mon Mar 11, 2013 4:55 pm
by Matt Oakes

Sorry - the line should read:

if (localStorage.getItem('Answer') == 'James Bond')


If statements in Java

Posted: Mon Mar 11, 2013 5:27 pm
by Kateryna Grynko