# Compound when statement

**URL:** https://cl.desmos.com/t/compound-when-statement/2648
**Category:** Questions
**Created:** [February 11, 2021, 5:25pm UTC](https://cl.desmos.com/t/compound-when-statement/2648 "2021-02-11T17:25:39Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![rbrigida](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/rbrigida/32/1449_2.png) [@rbrigida](https://cl.desmos.com/u/rbrigida)
#### Post date: [February 11, 2021, 5:25pm UTC](https://cl.desmos.com/t/compound-when-statement/2648/1 "2021-02-11T17:25:39Z")

</div>

This works fine, with one little issue…The second possible acceptable correct answer gives the message without having to submit. I tried adding " ans9.submitted and" after the ‘or’, but that created the wrong answer message for the first correct answer. Its a pretty minor thing, but my curiosity is getting the best of me.

content: “{message} {feedback}”

message = “When the second equation is solved for y, what’s the new equation?”

feedback = when ans9.submitted and ans9.latex=“y=1-3x” or ans9.latex=“y=-3x+1”  
“\n\n\n✅ Way to go ! !”  
when ans9.submitted "\n\n\n❌Wrong answer. Please try again. Remember Get y  
alone on the left!! \n\n "  
otherwise “”

---

<div class="post-metadata">

### Author: ![Mirko\_Danilovic](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/mirko_danilovic/32/1781_2.png) [@Mirko\_Danilovic](https://cl.desmos.com/u/Mirko_Danilovic)
#### Post date: [February 11, 2021, 6:10pm UTC](https://cl.desmos.com/t/compound-when-statement/2648/2 "2021-02-11T18:10:33Z")

</div>

You missed otherwise before second when.  
It should look:

````auto
content: message

message = "When the second equation is solved for y, what’s the new equation?${feedback}"

feedback = when ans9.submitted and ans9.latex="y=1-3x" or ans9.latex="y=-3x+1"
"\n\n\n✅ Way to go ! !" otherwise 
when ans9.submitted "\n\n\n❌Wrong answer. Please try again. Remember Get y
alone on the left!! \n\n "
otherwise ""```
btw, use slope and intercept function to avoid latex confusion. If there is an extra space in latex it cries and returns error.
````

---

<div class="post-metadata">

### Author: ![Daniel\_Grubbs](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_grubbs/32/719_2.png) [@Daniel\_Grubbs](https://cl.desmos.com/u/Daniel_Grubbs)
#### Post date: [February 11, 2021, 7:04pm UTC](https://cl.desmos.com/t/compound-when-statement/2648/3 "2021-02-11T19:04:17Z")

</div>

@Mirko_Danilovic only the final otherwise is necessary for when-otherwise (i.e. when when when when … otherwise). It’s not like other coding languages that use "if and “else if”.

@rbrigida You may need to add parentheses:

```auto
feedback = when ans9.submitted and (ans9.latex=“y=1-3x” or ans9.latex=“y=-3x+1”)...

```

---

<div class="post-metadata">

### Author: ![Mirko\_Danilovic](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/mirko_danilovic/32/1781_2.png) [@Mirko\_Danilovic](https://cl.desmos.com/u/Mirko_Danilovic)
#### Post date: [February 11, 2021, 7:10pm UTC](https://cl.desmos.com/t/compound-when-statement/2648/4 "2021-02-11T19:10:30Z")

</div>

@Daniel_Grubbs Thanks. It makes it easier to code.  
Then only thing that is missing in code is the $ sign infront of the feedback in content string.

---

<div class="post-metadata">

### Author: ![Daniel\_Grubbs](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_grubbs/32/719_2.png) [@Daniel\_Grubbs](https://cl.desmos.com/u/Daniel_Grubbs)
#### Post date: [February 11, 2021, 7:11pm UTC](https://cl.desmos.com/t/compound-when-statement/2648/5 "2021-02-11T19:11:58Z")

</div>

They may not have actually missed the $. It just disappears in the forum if you don’t use the triple backticks to display in the box.

---

<div class="post-metadata">

### Author: ![rbrigida](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/rbrigida/32/1449_2.png) [@rbrigida](https://cl.desmos.com/u/rbrigida)
#### Post date: [February 11, 2021, 10:47pm UTC](https://cl.desmos.com/t/compound-when-statement/2648/6 "2021-02-11T22:47:36Z")

</div>

Yes, the $ did disappear…and i did not know you could use parentheses …makes perfect sense now!! Opens up lots of other possibilities…

The latex check is good enough for now.

Thanks to both of you!
