Cant read a different entity in class template

I cant seem to get the class template to read a different sensor’s state to decide the class that should be used.

I have 2 sensors sensor.dogs_last_fed and sensor.dogsneedfood sensor.dogs_last_fed is simply a timestamp of the last time the dash button was pressed, while dogsneedfood is a timer whose state will be 0, 1 or 2 (increases based on how long since they last ate. The idea is to turn the background orange or red the longer they go without being fed.


   - name: DogFedTimestamp
       - sensor.dogs_last_fed
     text_template: 'Dogs last fed: ${entity.state ? entity.state : "unknown"}'
      class_template: '
      if (is_state(sensor.dogsneedfood, 0))
        return "green-background";
      else if (is_state(sensor.dogsneedfood, 1))
        return "orange-background";
      else if (is_state(sensor.dogsneedfood, 2))
        return "red-background";

Some formattings of the template will end up outputting the entire thing as a class but most will result in a error like this:

Uncaught SyntaxError: Unexpected identifier
URL: https://MYDOMAIN/floorplan
Line: 3, column: 5
Error: {}