0

I'm starting right now with coding on JS. There are a few things that I don't understand pretty well, and I'm a little bit confused because I have tried almost all, and I don't get to solve the error. Would someone provide me some help or guidance with this.

my code

function ImparPar(NumIp) {
   if(NumIp % 2 === 0) {
      return 'Par';
   } else {
      return 'Impar';
   }
}

5
  • What is function ImagePar(2) supposed to mean? Commented Nov 18, 2019 at 15:52
  • 2
    Welcome to SO! Please read why not upload images of code. Commented Nov 18, 2019 at 15:53
  • @ggorlen Sorry, I'm new on this forum, didn't know that. Thanks for the recommendation! Commented Nov 18, 2019 at 16:51
  • That's OK, but you can still edit your question to put the code in as text. The question is in danger of being closed otherwise. Commented Nov 18, 2019 at 16:53
  • Thx for the edit Norbert! I was just about to edit it by myself, but thanks. You guys are very nice on this site Commented Nov 18, 2019 at 17:00

1 Answer 1

1

Your function definition (on Line 1) has the following:

  • The function keyword
  • A function name (ImparPar)
  • A formal parameter (NumIP)

All these make this a function definition.

When you are calling the function later on in the code (line 13) you just need to call it by name. e.g.:

ImparPar(2);

When you are calling a function, you pass it - what is called - an actual parameter (in your case 2).

When you prefix it with the function keyword, it is interpreted as a function definition and therefore does not expect an actual parameter, and instead expects a formal parameter.

If you remove the function keyword from line 13 it should work as expected for you, and just execute the function.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.