Bolding individual words in strings

I want to bold one word in a string. The string needs to be built dynamically.

Here is my code in a Note component:
content: “{message} {feedback}”

functionName = “squareMe”

message = "

In the function ${functionName} on line 4, the value of myNum is …

feedback = when math1.submitted and math1.numericValue=3 “\n\n\n✅Good work!”
when math1.submitted “\n\n\n❌Wrong answer. Please try again.”
otherwise “”

And here is how I have attempted to bold the string in the editor:

Thank you for any help.

Rather than using the content: sink, just type what you want into the note, substituting variables where you need to. Then highlight and bold just the bits you want emboldened.

Thank you, but the contents of the note are dependent on two sources in another component, defined using a conditional. I don’t see how I would do that.

Here is the activity: S2 2021-2022 Week Seven Warm Ups (ICS) • Activity Builder by Desmos

What specifically would you like to bold?

Remove the content sink in the CL, then, in the component, type:
“In the function on line 4, the value of myNum is…”
Then put your cursor after “function”, click the {#} button and insert the functionName variable. At the end, click {#} again and insert the feedback variable. You can then just bold functionName.

I want to bold one word: squareMe

I also want to build my message dynamically, so that the contents of the note component contain “Good word!” or “Wrong answer. Please try again.” (See my original post. This is built inside the variable feedback.)

This would not present the dynamic result to the user that I envision. I want the result of the entry in the numeric box to cause the contents of this note to contain “Good work” or “Try again.” (See my original post. This information is stored in the variable feedback.

Thank you to those who have contributed. I don’t have my answer yet.

I have created a new activity which contains only the problem screen itself. (See the comment in the Note component for a problem description.)


Does this work for you?

By putting the variable feedback at the end it does in fact do what you intend:

(If it didn’t work when you tried, I assume because you left the content sink in. content sinks will overwrite anything typed in the component.)

OK. Thank you. This gives me hope.

Now, you assigned values (in the CL) to a variable called message. But you didn’t use it. Is this just an oversight? Is the variable not needed?

I didn’t rewrite yours, so I didn’t remove everything except for the content sink since that would stop it from working. message is not necessary.

Got it. Thank you for your help!

Well, look at that! Is that how you customarily handle such things? I like the compartmentalization a lot. Thank you!

Yes, that is how I usually do this. Allows you to use all sorts of formatting in the separate notes.

1 Like

I agree. I would put the feedback at the bottom so the first sentence is completed by the input.