Hi, practicing some javascript tasks and need some help with how to use a for loop to go through an array (which has 10 integers entered by the user). The for loop is to check if there are any duplicates of numbers and then i need to remove the duplicates. The task states that the code that counts the number of occurrences should be implemented in a function.

I have no difficulty prompting the user for the 10 integers and storing them in the array. Here's the code i have



    <script language = "JavaScript">
    //the variables
    var number = new Array (10);

    for (var x=0; x< number.length; x++)
        number[x] = window.prompt("Please enter 10 numbers");

    document.writeln("" + number);




Recommended Answers

All 3 Replies

Try to do two for loops to check if the variable in loop one is equal to the variable in loop two.

I hope this helps.

Have you tried to write this function? Post what you have so far, and we'll try to help you with it.

If you find a duplicate entry, and you remove it, what replaces it?

I was able to get this working by using two for loops, thanks for the help though

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.