Comp Layer Code Help

I am trying to type a CL that will give the message ‘Great Job’ when the kids get the answer correct, a message for when they don’t. My MathAnswer Boxes are labeled A and B and here is my code:
content:

when A.submitted

when A.numericValue=3 “Great job!”

otherwise “Check your work to see if you can find your mistake. If you need help, ask your teacher or a classmate.

otherwise “Try Again.”

On the last line I get the error: Syntax Error: undetermined String. What am I doing wrong?

The way that I have handled this is by adding a note under my input boxes and using conditions to display different messages…

I usually define the messages as variables like;

success="Good Job!"`
enter="Enter your answer in the box above"
wrong="Something's not quite right here. Check your work and try again"

Then you need to set conditions for each message;

content:
when not(A.submitted) "${enter}" when A.submitted and A.numericValue=3 
"${correct}" otherwise "${wrong}"

Thanks! Where do I put the define my variables at? In the same CL box or another place? I am totally new to this

All of the code should go in the note box.

It was close. (@Charlie_Paulson, she was attempting a nested when-otherwise which is valid, and actually computationally more efficient.) Just needed a few parentheses and you were missing and endquote for your first otherwise:

when A.submitted

(when A.numericValue=3 “Great job!”

otherwise "Check your work to see if you can find your mistake. 
If you need help, ask your teacher or a classmate." )

otherwise "Try Again."

Using @Charlie_Paulson’s variables:

content:
when A.submitted (when A.numericValue=3 "${success}" otherwise "${wrong}")
otherwise "${enter}" 

Thanks so much for your help!

Nested conditionals being computationally more efficient is debatable, given the conditional structure of Computation Layer. I agree that in some cases, nesting conditions makes for better organization, but in many, cleverly ordering your conditions is far more efficient. We talked a bit about it here: https://us5.campaign-archive.com/?u=ebec17c65ade785afdc700908&id=4f5ba29562

Maybe just the way I’ve been using them. For example, when having multiple when's that each have a .submitted condition, wouldn’t the code recheck whether it was submitted for every line? Whereas nested would check once, then go through each when if true, but also skip over all of them if false?

If you included a submitted condition in each line, yes. But CL will read through conditions from the top until it hits a true statement and then stop, so something like

when not(submitted) ""
when correct "✅"
otherwise "❌"

will do the same thing as

when submitted
   when correct "✅"
   otherwise "❌"
otherwise ""

Which only saves you a single line now, but can save a lot of condition duplicating when you scale to more complicated paths.

1 Like