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

  • Home
  • SEARCH
  • 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 8309181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:01:59+00:00 2026-06-08T19:01:59+00:00

I an working on a project for an Introductory Programming class so I’m using

  • 0

I an working on a project for an Introductory Programming class so I’m using basic javascript. This is our first project with functions and for some reason I can’t seem to make it work. I called all my variables and created the function before the program starts but for some reason it skips over running the function in my program. Any help would be appreciated.

This is just the beginning of my program, I don’t wanna write the rest of the code until I figure out why this part is broken, thats why the program doesn’t do anything but close the window if it doesnt pass the tests.

// 1 Declare Variables
var numTrees;
var counter = 0;
var answer = "no";

function treeFunction(answer, counter, numTrees) {
    while (answer == "no" && counter < 3) {
        if (numTrees == 5, 10) {
            answer = "yes";
        } else if (numTrees < 5 || numTrees > 10) {
            alert("That is an incorrect value.\nThe sample size should be less than 5 or greater than 10.\nPlease try again.");
            answer = "no";
            numTrees = prompt("Please reenter the amount of trees in your sample.");
            counter + 1;
        }
    }
    if (answer == "no") {
        alert("You have entered an incorrect number too many times.\nThe Program will now end.");
        window.open('', '_self', '');
        window.close();
    } else if (answer == "yes") {
        return;
    }
}
// 2 Prompt the Instructor for the number of Trees
numTrees = prompt("How many trees are in your sample?");
alert("You have entered: " + numTrees);
treeFunction(answer, counter, numTrees)
document.write(numTrees); {
    document.write("<br/> <br/>" + "End of Program.");
}
  • 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-08T19:02:01+00:00Added an answer on June 8, 2026 at 7:02 pm

    What you want is something more like this:

        if (numTrees < 5 || numTrees > 10) {
            alert("That is an incorrect value.\nThe sample size should be less than 5 or greater than 10.\nPlease try again.");
            answer = "no";
            numTrees = prompt("Please reenter the amount of trees in your sample.");
            counter + 1;
        } else {
            answer = "yes";
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT:This is from a working project of mine. Working. I declared some char arrays
While working a project tonight, I ended up using one .js resource file for
I'll try to be concise this time around! I'm still working Project Euler, this
I'm working on project using Java , in which IP address will be identity
I'm currently editing a working project with some experience on PHP. I know a
This is supposed to be a working project from my friend. He demonstrated the
I'm copying some objective c++ files over from another (working) project. I get no
I had a working project in VS2008 / .Net 3.5 using controls from the
I'm currently working on project with Haskell, and have found myself some trouble. I'm
I'm a student, so please bear with me! I've got some introductory Java (using

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.