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

Issue with "JavaScript basics": inconsistent usage of variables in functions #3158

Closed
nicl-dev opened this issue Mar 15, 2021 · 2 comments · Fixed by #3179
Closed

Issue with "JavaScript basics": inconsistent usage of variables in functions #3158

nicl-dev opened this issue Mar 15, 2021 · 2 comments · Fixed by #3179

Comments

@nicl-dev
Copy link

nicl-dev commented Mar 15, 2021

MDN URL: https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/JavaScript_basics

What information was incorrect, unhelpful, or incomplete?

When the user is asked to create the function setUserName he's presented with an example that concatenates the variable to a string:

function setUserName() {
  let myName = prompt('Please enter your name.');
  localStorage.setItem('name', myName);
  myHeading.textContent = 'Mozilla is cool, ' + myName;
}

In the next example it's done in the same way:

if(!localStorage.getItem('name')) {
  setUserName();
} else {
  let storedName = localStorage.getItem('name');
  myHeading.textContent = 'Mozilla is cool, ' + storedName;
}

Later he's asked to edit the setUserName function and the variable is now used inside the string:

function setUserName() {
  let myName = prompt('Please enter your name.');
  if(!myName) {
    setUserName();
  } else {
    localStorage.setItem('name', myName);
    myHeading.textContent = `Mozilla is cool, ${myName}`;
  }
}

In my opinion this could be pretty confusing to someone getting started with JavaScript or programming in general. I think users would benefit from consistency or a very short explanation here.

Specific section or headline?

  • Adding a personalized welcome message
  • A user name of null?
MDN Content page report details
@chrisdavidmills
Copy link
Contributor

I totally agree with you on this, thanks for reporting!

I've opened up #3179 to fix it. Let me know if you think it looks OK.

@nicl-dev
Copy link
Author

Cool, looks good to me!

wbamberg pushed a commit that referenced this issue Mar 18, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants