Login
Remember
IF Answers
Ask a Question

# Squiffy: How to fix if else error?

0 votes
171 views
asked Apr 27 in Authoring by Natas (17 points)

    if ( num1 < num2*0.10) {
         message = "poor"
    } else if ( etc ) {
         etc
    } else {
        etc
    }

The following is pseudo code that did not work well in practice. Is there some special way I must put if-else statements in Squiffy?

- squiffy

commented Apr 27 by Alex (486 points)
This needs more detail, what happens when you try it - any error messages? If you can give us an actual full example of a squiffy file that will help.
commented Apr 27 by Natas (17 points)
No the game doesnt load in the scratchpad. Assuming all the variables been globally defined how would I format an if then statement. It could be the number of tabs I am using.
commented Apr 28 by Alex (486 points)
We can't help unless we can see an example. The if statement in your question looks fine to me.
commented Apr 28 by Natas (17 points)
Here is an example of what I tried to enter in the scratchpad that made nothing appear:
https://gist.githubusercontent.com/anonymous/6533eae86b8e955827ea/raw/55f83abc74fbfbe30343179cc82e47045da23b98/example

## 1 Answer

0 votes
answered Apr 28 by Alex (486 points)
selected Apr 28 by Natas
Best answer

If you run your example and open your browser's developer console, you'll see an error like this:

    Uncaught ReferenceError: num1 is not defined

This is because to access Squiffy attributes from JavaScript, you need to use `get`. To set attributes, use `set`.

For example:

    if ( get("num1") < get("num2")*0.20 ) {
        set("message", "poor");
    } else if ( get("num1") < get("num2")*0.30 ) {
        set("message", "average");
    } else {
        set("message", "good");
    }

## Related questions

- Squiffy: How to force two variables to equal based off another variable?
- How to compare two variables in Squiffy?
- How to deal with large numbers in Squiffy?
- How to add a random number generator in Squiffy?
- Is there a way to turn Squiffy passage links into a regular link for accessibility purposes?

...