It's me again. Arrays are a mindbuster for me. I'm stuck again but I can't see the error.
Expand|Select|Wrap|Line Numbers
- <HTML>
- <HEAD>
- <SCRIPT>
- var lotto = [6, 8, 11, 26, 30, 38];
- var winst = ["2.068.200,00","24.220,00","1.208,00","28,80","2,50",];
- var lotto5 = [3, 8, 16, 18, 28, 38];
- function check(){
- var w5 = new Array();
- document.form.output.value += "\n" + "5 : ";
- for (var i in lotto) {
- for (var j in lotto5) {
- if (lotto[i] == lotto5[j]) {
- document.form.output.value += lotto[i] + " ";
- w5.length++;
- }
- }
- }
- for (var i in winst) {
- if (w5.length == winst[i]) {
- alert(winst[i]);
- }
- }
- }
- function execute() {
- check();
- }
- </SCRIPT>
- </HEAD>
- <BODY>
- <form name="form">
- <textarea name="output" cols="40" rows="10"></textarea>
- <br>
- <input type="button" value="Execute" onclick="javascript:execute()">
- <input type="reset" value="reset">
- </form>
- </BODY>
- </HTML>
These are two compare functions which compare arrays. The first one works perfectly. It shows the common numbers in the textarea.
The second one is the problem.
What it should do is get the total amount of matching numbers and then show the value which corresponds with it in the array "winst".
So if w5.length is 2 then the alert should display winst[2]
But somewhere inside the script I've messed up.
If anyone sees it, I would appreciate it if you could point it out.
thanks,
Cainnech