Matt Oakes
Posts: 0
Joined: Fri Mar 01, 2013 12:45 pm

If statements in Java

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

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

If statements in Java

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

Matt Oakes
Posts: 0
Joined: Fri Mar 01, 2013 12:45 pm

If statements in Java

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

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

If statements in Java

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

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

Matt Oakes
Posts: 0
Joined: Fri Mar 01, 2013 12:45 pm

If statements in Java

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

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

If statements in Java

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.

Matt Oakes
Posts: 0
Joined: Fri Mar 01, 2013 12:45 pm

If statements in Java

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

Matt Oakes
Posts: 0
Joined: Fri Mar 01, 2013 12:45 pm

If statements in Java

Sorry - the line should read:

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

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

If statements in Java

Return to “Issues”