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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:54:52+00:00 2026-06-07T04:54:52+00:00

This does not seem to be working I am not sure how to get

  • 0

This does not seem to be working I am not sure how to get this while loop to work correctly any help would be appreciated.

function getProductCode() {
   productCode = parseInt(prompt("Enter Product Code: "));
   while (productCode < 1 || > 9999) 
   {
      document.writeln("Error! the product Code must be between 1 - 9999");
      parseInt(prompt("Enter Product Code: "));
   }
   return productCode
}

getProductCode()
  • 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-07T04:54:54+00:00Added an answer on June 7, 2026 at 4:54 am

    You’re missing an operand (productCode) at the left side:

    while (productCode < 1 || productCode > 9999) 
                              ^^^^^^^^^^^
    

    And:

    • Supply a radix to parseInt. When unspecified, 010 becomes 8 (octal literal).
    • Do not leak variables to the global scope, use var to declare local variables.
    • Invert your logic, or use isNaN. When an invalid number is supplied (NaN), your loop should not stop.
    • It’s better to move the message from document.writeln to the dialog.
    • Assign the new value to productCode. Otherwise, you won’t get far…
    • Important: Dialogs can be disabled in browsers. Do not loop infinitely many times, but add a treshold.

    Final code which takes care of the first 5 bullet points:

    function getProductCode() {
       var productCode = parseInt(prompt("Enter Product Code: "), 10);
       while (!(productCode >= 1 && productCode <= 9999)) {
          productCode = parseInt(prompt("Error! the product Code must be between 1 - 9999\nEnter Product Code: "), 10);
       }
       return productCode;
    }
    

    I have not implemented the treshold, it’s up to you to do that.

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

Sidebar

Related Questions

I assumed joinable would indicate this, however, it does not seem to be the
I been working on this code for a while and can't seem to get
Is there a particular way to initialize an IList<T> ? This does not seem
I need a good OLEDate java implementation, and this one does not seem to
I used this code previously in netbeans 6.9.1 but it does not seem to
I've been trying to fix this error: {exception:Persistent class \Class org.myapp.model.Account does not seem
This does NOT work: Sub X() Dim A As Access.Application Set A = CreateObject(Access.Application)
This does not really apply to any language specifically, but if it matters I
can anyone tell me why this does not work Excel.Worksheet ws_res = (Excel.Worksheet) wb.Worksheets.Add(mis,
I can't seem to get this toString() method to work? The deepToString method works

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.