Skip to content
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

Add explanation of Unary plus (+) operator to Extract for money strings exercise #3685

Open
martinDolan opened this issue Apr 23, 2024 · 3 comments

Comments

@martinDolan
Copy link

martinDolan commented Apr 23, 2024

The solution to Extract the money problem, uses the unary + operator, however, I don't see that explained anywhere in the Strings section. Adding an explanation of that would be helpful.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unary_plus

function extractCurrencyValue(str) {
  return +str.slice(1);
}
@martinDolan martinDolan changed the title Add explanation of Unary plus (+) operator Add explanation of Unary plus (+) operator to Extract the money strings exercise Apr 23, 2024
@martinDolan martinDolan changed the title Add explanation of Unary plus (+) operator to Extract the money strings exercise Add explanation of Unary plus (+) operator to Extract for money strings exercise Apr 23, 2024
@Alexandre887
Copy link
Member

I don't see that explained anywhere in the Strings section. Adding an explanation of that would be helpful.

This has already been mentioned in the article "Basic operators, maths", there is even a task on this topic. If a potential reader hasn't internalized the information in this chapter, and in the "JavaScript Fundamentals" section in general, I don't think reading the "Strings" article in the "Data Types" section will do him any good.

@martinDolan
Copy link
Author

Understandable assuming everyone reads from beginning to end. I didn't read the Basic operators, maths section, but maybe a link to that would be useful to some.

@Alexandre887
Copy link
Member

Don't see much point to it. I don't think anyone resorts to solving such problems and using string methods without knowing such elementary things as unary plus. It is equivalent to explaining what an object is in the Classes chapter.

But, for that matter, then it would be more logical to replace +prompt(...) with Number(prompt(...)) instead of explaining the purpose of the $+$ in the notation. But even this is, in my opinion, an unnecessary measure.

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

No branches or pull requests

2 participants