0

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

<html>

<head>
    <title>UniqueNumbers</title>
</head>

<body>
    <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);

    </script>

</body>

</html>
3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by laura301019
0

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.

0

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?

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.