Putting messages in textView

Hi, I want to thank Chris for this course. I am working on my first App. It is a nutrition app and it takes input from a nutrition label and gives the meal a heathfulness rating and feedback if the rating for a category is low. Right now I’m trying to get the messages to appear in a text view, but I have had to make multiple text view fields for each message like “meal is high in fat”. How do I write the code to make one or more messages display as needed in a single text view. I’m including what I have below.

    let saturatedFatMessage = " Your meal is high in saturated fat. Eating too much saturated fat can raise colesterol levels and contribute to heart disease and stroke"
    let sodiumMessage = " Your meal is high in sodium.  Most sodium comes from sodium chloride-table salt. To reduce salt in your diet avoid prepackaged foods and dining out"
    let sugarMessage = " This meal is high in added sugar. The American Heart Association recommends less than 25 grams added sugar per day for women and less than 37.5 grams per day for men"
        
          
         textViewTop.text = "Your recipe earned \(totalScore)"
    
    if sugarValue == 1.0
    {
    
        textViewSugar.text = "Warning:(sugarMessage)" }

    
    if saturatedFatValue == 1.0 { textViewSaturatedFat.text = "Warning: (SaturatedFatMessage)" }

Thanks,
Lea

You could first “build” the message that will be displayed and then do textViewTop.text = completeMessage

var completeMessage = “”
if sugarValue == 1.0
    {
    
        completeMessage = "Warning:(sugarMessage)"
 }

   
    if saturatedFatValue == 1.0 { completeMessage = completeMessage + “\n” "Warning: (SaturatedFatMessage)" }

Then finally do
textViewTop.Text = completeMessage

Thanks for the suggestion. It looks like it should work, but I am getting an error I don’t know how to fix. :String literal is unused. The simulator only shows the sugarMessage. Help please!

         textViewTop.text = "Your recipe earned \(totalScore)"
    
      var completeMessage = ""

        if sugarValue == 1.0
           { completeMessage = "Warning:\(sugarMessage)"
        }
  

   if saturatedFatValue == 1.0 { completeMessage = completeMessage + "\n"
    "Warning:\(saturatedFatMessage)" }
    
    
    if totalFatValue == 1.0 {
    completeMessage =
     completeMessage + "\n"
    "Warning:\(fatMessage)" }
    
    
        textViewMessage.text = completeMessage

You haven’t join these strings together. You need a + after the "\n".

Same issue here:

thanks! it’s working now.