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 8660753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:20:11+00:00 2026-06-12T16:20:11+00:00

I’m new to the Javascript world and trying to figure out this assignment my

  • 0

I’m new to the Javascript world and trying to figure out this assignment my teacher assigned. Here is his description of what is expected:

  1. Build a function that will start the program. Please call it start()

  2. From the start() function, call a function called getValue()

  3. The getValue() function will get a number from the user that will be squared.

  4. Also from the start function, call a function called makeSquare()

  5. The makeSquare() function will square the number that was received by the user in the getValue() function.

  6. Make sure that you display the results of squaring the number inside of the makeSquare() function.

Here is what I have so far:

function start() {

    getValue();
    getSquare();
}

function getValue() {

    var a = prompt("Number please")
}

function getSquare() {

    var b = Math.pow(a)
    document.write(b)
}

start()

This assignment doesn’t have to be working with any HTML tags. I’ve only got the prompt box to work, nothing else does though. Am I using variables in a way that can’t be used?

  • 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-12T16:20:12+00:00Added an answer on June 12, 2026 at 4:20 pm

    You were close. But it seems that you don’t understand scoping and how exactly to use the pow function.

    Math.pow:

    Math.pow takes two parameters, the base and the exponent. In your example, you only provide the base. That will cause problems as the function will return the value undefined and set it to b. This is how it should have looked (if you wanted to square it):

    Math.pow(a, 2);
    

    Scoping:

    Every function has it’s own scope. You can access other variables and functions created outside the function from within the function. But you cannot access functions and variables created inside another function. Take the following example:

    var c = 5;
    
    function foo() { // we have our own scope
       var a = c; // Okay
    }
    
    var b = a; // NOT okay. a is gone after the function exits.
    

    We could say that a function is private. The only exception is that we can return a value from a function. We return values using the return keyword. The expression next to it is the return-value of the function:

    function foo() {
        return 5;
    }
    
    var a = foo(); // a === 5
    

    foo() not only calls the function, but returns its return-value. A function with no return-value specified has a return value of undefined. Anyway, in your example you do this:

    function getValue() {
        var a = prompt("Number please")
    }
    

    and access it like this:

    // ...
    var b = Math.pow(a)
    

    Do you see the error now? a is defined in the function, so it can’t be accessed outside of it.

    This should be the revised code (Note: always use semicolons. I included them in for you where necessary):

    function start() {
        getSquare();
    }
    
    function getValue() {
    
        var a = prompt("Number please");
        return a;
    }
    
    function getSquare() {
    
        var b = Math.pow(getValue(), 2); // getValue() -> a -> prompt(...)
        document.write(b);
    }
    
    start();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

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.