PHP | Highschool Sweetheats function 4

Hi all, I need help with the function 4 of the Highschool Sweetheats exercise in php. The test doesn’t pass and couldn’t identify what is wrong in my code. :frowning:

<?php

class HighSchoolSweetheart
{
    public function firstLetter(string $name): string
    {   
        $firstLetter = trim(substr($name, 0, 1));
        return $firstLetter;
        throw new \BadFunctionCallException("Implement the function");
    }

    public function initial(string $name): string
    {
        $initial = strtoupper($this->firstLetter($name));
        $initial .= '.';
        return $initial;
        throw new \BadFunctionCallException("Implement the function");
    }

    public function initials(string $name): string
    {
        $fullName= explode(" ", $name);
        $firstName = $fullName[0];
        $lastName = $fullName[1];

        $firstLetterFirstName = $this->initial($firstName);
        $firstLetterLastName = $this->initial($lastName);
        $initials = $firstLetterFirstName .= " $firstLetterLastName";
        
        return $initials;
        
        throw new \BadFunctionCallException("Implement the function");
    }

    public function pair(string $sweetheart_a, string $sweetheart_b): string
    {
        $initials_a = $this->initials($sweetheart_a);
        $initials_b = $this->initials($sweetheart_b);

        $heart ="
        ******       ******
       **      **   **      **
     **         ** **         **
    **            *            **
    **                         **
    **     $initials_a  +  $initials_b     **
     **                       **
       **                   **
         **               **
           **           **
             **       **
               **   **
                 ***
                  *";

        return $heart;
    }
}```
  1. Please use codeblocks and not images for sharing text.
  2. Compare the expected and actual, line by line. Specifically, compare the first line of each.

Hi IsacG,

I am experience exactly the same issue and can’t find the solution. The expected and actual seems the same, what should be compared exactly?

Thanks, Tobi

  1. Could you share your code and the test output using a codeblock?
  2. You probably want to pay attention to the first/last lines and the first/last bit of each line.

HI Isaac,

thanks for your quick reply. Attached my code:

<?php

class HighSchoolSweetheart
{
    public function firstLetter(string $name): string
    {
        $name = trim($name," ");
        return $name[0];
    }

    public function initial(string $name): string
    {
        $name_dot = strtoupper($this->firstLetter($name)) . ".";
        return $name_dot;
    }

    public function initials(string $name): string
    {
        $names = explode(" ", $name);
        $firstname = $this->initial($names[0]);
        $secondname = $this->initial($names[1]);
        return $firstname . " " . $secondname;

    }

    public function pair(string $sweetheart_a, string $sweetheart_b): string
    {
            return <<<END
         ******       ******
       **      **   **      **
     **         ** **         **
    **            *            **
    **                         **
    **     {$this->initials($sweetheart_a)}  +  {$this->initials($sweetheart_b)}     **
      **                       **
        **                   **
          **               **
            **           **
              **       **
                **   **
                  ***
                   *
END;

        }
}


The error:

HighSchoolSweetheartTest::testPair
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'     ******       ******\n
-   **      **   **      **\n
- **         ** **         **\n
-**            *            **\n
-**                         **\n
-**     A. B.  +  C. D.     **\n
- **                       **\n
-   **                   **\n
-     **               **\n
-       **           **\n
-         **       **\n
-           **   **\n
-             ***\n
-              *'
+'         ******       ******\n
+       **      **   **      **\n
+     **         ** **         **\n
+    **            *            **\n
+    **                         **\n
+    **     A. B.  +  C. D.     **\n
+      **                       **\n
+        **                   **\n
+          **               **\n
+            **           **\n
+              **       **\n
+                **   **\n
+                  ***\n
+                   *'

/mnt/exercism-iteration/HighSchoolSweetheartTest.php:94

Looks for me the same, but maybe a oversee a simple thing. Thanks again.

Consider the middle line:

-**     A. B.  +  C. D.     **\n
+    **     A. B.  +  C. D.     **\n

Do those look the same? As I mentioned earlier, pay attention to the start and ends of lines :slight_smile:

oh wow, now I feel stupid haha :D Thanks again Isaac for the push in the right direction :D

You’re very welcome. We’ve all been there at times :smiley: