Ich versuche, meinen Code die maximale Anzahl an Handys und Zubehör zu kaufen. Ein Telefon kostet 99,99 und ein Zubehör kostet 9,99. Ich habe 1000 auf meinem Bankkonto. Wie kann ich meinen Code den maximalen Betrag kaufen? Mein Code kauft derzeit 9 Telefone und 9 Zubehörteile. Es sollte 9 Telefone und 10 Zubehör kaufen, anstatt 9.Wie man Schleife maximalen Betrag kaufen macht?
const ACCESSORY = 9.99;
const PHONE = 99.99;
var balance = 1000;
var total = 0;
var phones_total = 0;
var accessories_total = 0;
while (((total + PHONE) || (total + ACCESSORY)) < balance) {
total = total + PHONE;
phones_total = phones_total + 1;
if ((total + ACCESSORY) < balance) {
total = total + ACCESSORY;
accessories_total = accessories_total + 1;
}
}
console.log("total = " + total);
console.log("phones = " + phones_total);
console.log("accessories = " + accessories_total);
10 Telefone + 10 Zubehör kostet 1099,80, das ist mehr als Sie sich leisten können. – Barmar
Ich denke, du musst dein Problem besser erklären. – Carcigenicate
'while (((gesamt + PHONE) || (gesamt + ZUBEHÖR))
Barmar