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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:41:06+00:00 2026-06-16T09:41:06+00:00

I have been trying for days to get this to work. I have the

  • 0

I have been trying for days to get this to work. I have the basic code but every time I try to get the last requirement added, I break the code. I’m sure I am missing a lot and that’s why I can’t add the alert box with the count of displays. So it asks the users name, the number of times they want to see and alert box and if they enter invalid answers they see alert boxes telling them to enter a correct value. The last part that I am stuck on is the value the user enters determines how many alert boxes show their name and the box needs to say which box it is. So, <Name> this is time number <count of displays> of <total time to display>. I was trying different things with limiting and FOR , with the user Y variable being the limiter. Any clues or help would be greatly appreciated.

<!DOCTYPE html>
<html>
<body>

<p>Please enter your name followed by how many times you would like to be alerted.</p>

<button onclick="myFunction()">Start</button>



<script>


function myFunction() {
    var x;

    var name = prompt("Please enter your name", "");
    if (name == null || name == "") {
        alert("Please input a name.");

        return false;
    }
    else {
        var y;
        var y = prompt("Please enter a number between 1-10");
        if (y == null || y == "") {
            alert("Please input a number for the times to alert the name.");
            return false;
        }
        if (y > 10) {
            alert("Please input a number between 1 and 10.")
            var y = prompt("Please enter a number between 1-10");

        }
        if (y <= 0) {
            alert("Please input a number great than zero.")
            var y = prompt("Please enter a number between 1-10");

        }
    }
}

</script>

</body>
</html>
  • 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-16T09:41:07+00:00Added an answer on June 16, 2026 at 9:41 am

    This gets rid of most of your alert statements and keeps prompt‘ing until a valid value is submitted.

    function myFunction() {
        var x,y,name = "";
        while(name.length < 1) {
            name = prompt("Please enter your name", "");
        }
    
        while(!((y > 0) && (y <11))) {
           y = prompt("Please enter a number between 1-10");
        }
    
        for(x = 0; x < y; x++) {
           alert(name);
        }
    }
    

    Working example:

    http://jsfiddle.net/DwxmT/

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

Sidebar

Related Questions

I have been trying for days to get this code to work, but I
I've been trying to get this to work for the last two days but
I have been trying to get this to work for about three solid days
I have been trying to get this to work for a few days. Basically
I've been trying for the last two days to get this to work with
So I have been trying to get this to work 2 days and I
I have been trying to days now to get this website completed ... however,
So I have been trying for hours to get this to work and I
Hi I have been trying to get this script http://jsbin.com/ipajo5/ working but using .live()
I've been trying to get this to work for days and I'm tearing my

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.