Skip to content

[LISFT0123] Assebe Kleinert #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

Assebe
Copy link

@Assebe Assebe commented Jan 17, 2023

No description provided.

console.log(reversedHacker);

// 3.3
if(hacker1 < hacker2){
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this exercise you needed to check which name comes first in alphabetical order, for this you have specific method called localCompare() that does exactly that.

The localCompare() method always returns 1, 0 or -1.

  • Negative when the referenceStr occurs before compareString
  • Positive when the referenceStr occurs after compareString
  • Returns 0 if they are equivalent

So, one of the ways you could have done this part is by storing the result of the localCompare() in a variable, and change the conditions to check if the result is positive negative or zero.

let compare = hacker1.localeCompare(hacker2)

if (compare === -1) {
  console.log("The driver name goes first");
} else if (compare === 1) {
  console.log("Yo, the navigator goes first definitely.");
} else {
  console.log("What?! You both have the same name?");
}

@joaopdg
Copy link

joaopdg commented Jan 17, 2023

Great job on the lab Assebe, next time try to do the bonus!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants