Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8626305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:59:39+00:00 2026-06-12T07:59:39+00:00

I am currently learning javascript and am a litte confused with passing parameters through

  • 0

I am currently learning javascript and am a litte confused with passing parameters through functions, I was hoping someone could give a clearer explanation

I have the following simple code

     //generate random number
     var number = Math.round(Math.random()*10 + 1);

     //Ask user for name
     var playerName = prompt("What is your name?");

     //Prompt for intro
    var weclome =   alert("Hello " + playerName + " Welcome to Guess the Number");
    console.log(number);

    var playerGuess = prompt("What is your guess ");

    if (playerGuess !== null) guess(playerGuess);

   function guess(pGuess){ 
    if(pGuess == number) {
     alert("Congratulations you have guessed correctly");
    } else {
     alert("Unlucky, please try again");
  }  
}

As you can see its ust a simple guess the number game. From what i understand so far I have assigned the variable playerGuess as the result of the input from the prompt, which I pass through the guess function. What I dont understand is that i have called the param pGuess within the guess function. My understanding is that this should not work, but yet it does, how does pGuess know to get its value from playerGuess.

Am I looking at this in totally the wrong way, I would really like to understand this

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:59:40+00:00Added an answer on June 12, 2026 at 7:59 am

    What you’re doing with this line (note the function keyword):

    function guess(pGuess){
    

    is defining a reusable chunk of code (a “function”) which takes a single parameter. When that parameter arrives, it’s accessible by the name pGuess during the following block of code, which lasts until the matching }.

    What you’re doing with this line (note we don’t have the function keyword any more):

    guess(playerGuess);
    

    is calling that function using the current value of the playerGuess variable. So you’re passing that value into the function where it places it in the previously defined pGuess variable for the scope of that function call

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently learning Javascript, and I'd like to create my own Lorem Ipsum
I am currently learning Object oriented Javascript but it seems that the alert is
I'm currently learning C and am struggling with how to iterate through an array
I'm new to JavaScript, and I'm currently learning about the so-called for... in loop.
I'm currently learning JavaScript, but I'm very weak on the fundamentals. I'm trying to
I am currently learning advanced JavaScript, with an aim to build a standards compliant
I'm currently learning JavaScript, and I don't understand why it is important to encode
i am currently learning about javascript namespaces as i build a website and i
I'm learning JavaScript and I'm currently trying to figure out why (in Spidermonkey )
I am currently learning javascript and am trying to make a quiz in javascript

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.