{"action":"created","issue":{"url":"https://api.github.com/repos/JirkaDellOro/EIA2/issues/222","repository_url":"https://api.github.com/repos/JirkaDellOro/EIA2","labels_url":"https://api.github.com/repos/JirkaDellOro/EIA2/issues/222/labels{/name}","comments_url":"https://api.github.com/repos/JirkaDellOro/EIA2/issues/222/comments","events_url":"https://api.github.com/repos/JirkaDellOro/EIA2/issues/222/events","html_url":"https://github.com/JirkaDellOro/EIA2/issues/222","id":372537924,"node_id":"MDU6SXNzdWUzNzI1Mzc5MjQ=","number":222,"title":"Willkürliche Anzahl an generierten Uno Karten","user":{"login":"sebifyy","id":43846468,"node_id":"MDQ6VXNlcjQzODQ2NDY4","avatar_url":"https://avatars2.githubusercontent.com/u/43846468?v=4","gravatar_id":"","url":"https://api.github.com/users/sebifyy","html_url":"https://github.com/sebifyy","followers_url":"https://api.github.com/users/sebifyy/followers","following_url":"https://api.github.com/users/sebifyy/following{/other_user}","gists_url":"https://api.github.com/users/sebifyy/gists{/gist_id}","starred_url":"https://api.github.com/users/sebifyy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sebifyy/subscriptions","organizations_url":"https://api.github.com/users/sebifyy/orgs","repos_url":"https://api.github.com/users/sebifyy/repos","events_url":"https://api.github.com/users/sebifyy/events{/privacy}","received_events_url":"https://api.github.com/users/sebifyy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-10-22T14:11:31Z","updated_at":"2018-10-23T08:52:31Z","closed_at":null,"author_association":"NONE","body":"Hallo,\r\nmein Code erzeugt willkürlich viele Uno Karten, manchmal sogar gar keine. Ich habe eine User Eingabe implementiert jedoch kommen nie die richtige Anzahl der Karten raus.\r\n\r\n`namespace unogame {\r\n\r\n    var color: string[] = [\"#ff5454\", \"#fffc54\", \"#56ff54\", \"#5495ff\"];\r\n    var cards_numbers: string[] = [\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\"];\r\n    var cards_Zero: string = \"0\";\r\n    var cards_special: string[] = [\"Aussetzen\", \"RW\", \"plus2\"];\r\n    var cards_black: string[] = [\"Joker\", \"plus4\"];\r\n\r\n    // FUNKTION UM ZUFAELLIGE ZAHLEN ZU GENERIEREN ZWISCHEN MIN/MAX\r\n    function randomBetween(min: number, max: number): number {\r\n        return Math.floor(Math.random() * (max - min + 1) + min);\r\n    }\r\n\r\n    var i: string = prompt(\"Wie viele Karten sollen ausgeteilt werden?\");\r\n    var counter: number = Number(i);\r\n    // GENERELLE FOR SCHLEIFE DIE 5 MAL DURCHLAEUFT\r\n    for (var u: number = 0; u < counter; u++) {\r\n        var card: string = \"\";\r\n        var r_color: number = randomBetween(1, 1000);\r\n        console.log(r_color);\r\n\r\n\r\n        if (r_color <= 74) { // WENN r_color KLEINER ALS 74 DANN ENTSCHEIDE ZWISCHEN JOKER/PLUS4 KARTE\r\n            console.log(\"BLACK CARD\");\r\n\r\n            var r_black: number = randomBetween(0, 1);\r\n            card = cards_black[r_black]\r\n        }\r\n        else {\r\n            console.log(\"COLORED CARD\")\r\n\r\n            var r_Zero: number = randomBetween(0, 1000);\r\n\r\n            //ZERO KARTE\r\n            if (r_Zero <= 37) {\r\n                //card = \"Zero\"\r\n\r\n                //FARBE AUSWAEHLEN\r\n                var WhichColor = randomBetween(0, 3);\r\n                console.log(\"FARBE: \" + WhichColor);\r\n                switch (WhichColor) {\r\n                    case 0: //RED\r\n                        var red: string = color[WhichColor];\r\n                        placeDiv(red, 50, 50, 75, 150, \"0\");\r\n                        card = \"RED ZERO\";\r\n                        break;\r\n\r\n                    case 1: //YELLOW\r\n                        var yellow: string = color[WhichColor];\r\n                        placeDiv(yellow, 50, 50, 75, 150, \"0\");\r\n                        card = \"YELLOW ZERO\";\r\n                        break;\r\n\r\n                    case 2: //GREEN\r\n                        var green: string = color[WhichColor];\r\n                        placeDiv(yellow, 50, 50, 75, 150, \"0\");\r\n                        card = \"GREEN ZERO\";\r\n                        break;\r\n\r\n                    case 3: //BLUE\r\n                        var blue: string = color[WhichColor];\r\n                        placeDiv(blue, 50, 50, 75, 150, \"0\");\r\n                        card = \"BLUE ZERO\";\r\n                        break;\r\n                }\r\n            }\r\n\r\n            //WENN KEINE NULL, DANN NUMMER AUSWAEHLEN\r\n            else if (r_Zero > 37 && r_Zero < 760) {\r\n                var r_Number: number = randomBetween(1, 9);\r\n\r\n                //FARBE AUSWAEHLEN\r\n                var WhichColor = randomBetween(0, 3);\r\n                console.log(\"FARBE: \" + WhichColor);\r\n\r\n                switch (WhichColor) {\r\n                    case 0: //RED\r\n                        var red: string = color[WhichColor];\r\n                        placeDiv(red, 50, 50, 75, 150, <string><any>r_Number);\r\n                        card = String(r_Number);\r\n                        break;\r\n\r\n                    case 1: //YELLOW\r\n                        var yellow: string = color[WhichColor];\r\n                        placeDiv(red, 50, 50, 75, 150, <string><any>r_Number);\r\n                        card = String(r_Number);\r\n                        break;\r\n\r\n                    case 2: //GREEN\r\n                        var green: string = color[WhichColor];\r\n                        placeDiv(red, 50, 50, 75, 150, <string><any>r_Number);\r\n                        card = String(r_Number);\r\n                        break;\r\n\r\n                    case 3: //BLUE\r\n                        var blue: string = color[WhichColor];\r\n                        placeDiv(red, 50, 50, 75, 150, <string><any>r_Number);\r\n                        card = String(r_Number);\r\n                        break;\r\n                }\r\n\r\n            }\r\n\r\n            //SPECIAL KARTE    \r\n            else if (r_Zero >= 760) {\r\n                var r_Special: number = randomBetween(0, 2);\r\n\r\n\r\n                switch (r_Special) {\r\n                    case 0: //RED\r\n                        var red: string = color[WhichColor];\r\n                        placeDiv(red, 50, 50, 75, 150, <string><any>r_Special);\r\n                        card = String(r_Special);\r\n                        break;\r\n\r\n                    case 1: //YELLOW\r\n                        var yellow: string = color[WhichColor];\r\n                        placeDiv(yellow, 50, 50, 75, 150, <string><any>r_Special);\r\n                        card = String(r_Special);\r\n                        break;\r\n\r\n                    case 2: //GREEN\r\n                        var green: string = color[WhichColor];\r\n                        placeDiv(green, 50, 50, 75, 150, <string><any>r_Special);\r\n                        card = String(r_Special);\r\n                        break;\r\n                }\r\n            }\r\n        }\r\n        console.log(card);\r\n        console.log(\"++++++++++++++++++++++++++++++++++++\");\r\n\r\n\r\n    }\r\n\r\n    function placeDiv(_color: string, _x: number, _y: number, _width: number, _height: number, text: string): void {\r\n        let div: HTMLDivElement = document.createElement(\"div\");\r\n        document.body.appendChild(div);\r\n\r\n        div.setAttribute(\"id\", \"Karte#\" + u) //div ID in Abh�ngigkeit von _x (aktuelle Karte die gegeben wird)\r\n\r\n        document.getElementById(\"Karte#\" + u).innerHTML = text;\r\n\r\n        let s: CSSStyleDeclaration = div.style;\r\n        s.border = \"3px solid black\";\r\n        s.position = \"relative\";\r\n        s.backgroundColor = _color;\r\n        s.width = _width + \"px\";\r\n        s.height = _height + \"px\";\r\n        s.left = _x + \"px\";\r\n        s.top = _y + \"px\";\r\n    }\r\n}\r\n\r\n\r\n\r\n\r\n`"},"comment":{"url":"https://api.github.com/repos/JirkaDellOro/EIA2/issues/comments/432157395","html_url":"https://github.com/JirkaDellOro/EIA2/issues/222#issuecomment-432157395","issue_url":"https://api.github.com/repos/JirkaDellOro/EIA2/issues/222","id":432157395,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMjE1NzM5NQ==","user":{"login":"R4Pi3R","id":25267269,"node_id":"MDQ6VXNlcjI1MjY3MjY5","avatar_url":"https://avatars2.githubusercontent.com/u/25267269?v=4","gravatar_id":"","url":"https://api.github.com/users/R4Pi3R","html_url":"https://github.com/R4Pi3R","followers_url":"https://api.github.com/users/R4Pi3R/followers","following_url":"https://api.github.com/users/R4Pi3R/following{/other_user}","gists_url":"https://api.github.com/users/R4Pi3R/gists{/gist_id}","starred_url":"https://api.github.com/users/R4Pi3R/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/R4Pi3R/subscriptions","organizations_url":"https://api.github.com/users/R4Pi3R/orgs","repos_url":"https://api.github.com/users/R4Pi3R/repos","events_url":"https://api.github.com/users/R4Pi3R/events{/privacy}","received_events_url":"https://api.github.com/users/R4Pi3R/received_events","type":"User","site_admin":false},"created_at":"2018-10-23T08:52:31Z","updated_at":"2018-10-23T08:52:31Z","author_association":"NONE","body":"Ok, ich hab jetzt mal schnell drüber geschaut und mir sind ein paar Sachen aufgefallen\r\n1. Das Script sollte nicht im <body> referenziert sein.\r\n2. Es werden tatsächlich \"willkürlich\" Karten erzeugt, da der Algorithmus trotz geringer Wahrscheinlichkeit nicht ausschließt, dass eine Karte öfter als erlaubt erzeugt wird.\r\n3. Die Anzahl der Karten ist manchmal falsch, da für die schwarze plus4 Karte placeDiv überhaupt nicht aufgerufen wird\r\n4. Für die Darstellung der anderen Karten ist in der Konsole auffällig, dass bei einigen \"colored cards\" keine Farbe aufgeführt wird. Außerdem passt der Inhalt der Karte oftmals nicht zu der zufällig generierten Zahl.\r\n\r\nAllgemein: Wie in der Aufgabe indirekt verlangt wird, sollte zunächst ein Kartendeck angelegt werden, in dem alle Karten so oft wie erlaubt vorhanden sind. Aus diesem kann dann eine zufällige Karte ausgewählt und dargestellt werden. Das macht sowohl die Auswahl, als auch den Ausschluss deutlich einfacher.\r\nDas ist keine Schelte, aber aus meiner Sicht ergibt es wenig Sinn an Fehlerhaftem Code herumzudoktorn, wenn, selbst wenn er funktioniert, nicht das verlangte Ergebnis zu erreichen ist."}}
{"actor":{"display_login":"R4Pi3R"}}