Мне стыдно опубликовать мою попытку в самом первом практическом упражнении в «Не знаешь JavaScript: взлет и вперед». Однако я надеюсь, что кто-то может сказать мне, что (безусловно, несколько вещей) я делаю здесь неправильно.Я застрял на работе, поэтому использую JS-компилятор AWS Cloud 9. Текущая ошибка, которую я постоянно получаю, связана с каждой из моих подсказок. Она гласит: «ReferenceError: приглашение не определено». Использую ли я правильный синтаксис для цикла while?
Кроме того, я чувствую, что StackOverflow предназначен для более конкретных вопросов и вопросов более высокого уровня. Куда можно обратиться с основными тупыми вопросами для начинающих?
// Declare the prices of the various phones& accessories in stock and tax
rate.
const TAX_RATE = 0.09;
const IPHONE = 500;
const GALAXY = 469;
const WINDOZE_PHONE = 369;
const EL_CHEAPO = 69;
const SCREEN_PROTECTOR = 10;
const DONGLE = 12;
const CASE = 20;
const CAR_CHARGER = 20;
//initialize global variables.
var accessories =0;
var chosenPhone;
//create a function we can call each time we need to check which phone is
selected.
function whichPhone(phonePrompt){
var phonePrompt = prompt("Enter 1, 2, 3, or 4 for an iPhone, Samsung
Galaxy," + "Windows Phone, or Cheap Phone respectively.");
switch (phonePrompt){
case (1):
chosenPhone = IPHONE;
case (2):
chosenPhone = GALAXY;
case (3):
chosenPhone = WINDOZE_PHONE;
case (4):
chosenPhone = EL_CHEAPO;
break;
default:
alert("You gotta enter a number 1 through 4. If not, ya broke it");
}
}
//create a function to add the price for each accessory added to the bill
function upsell(confirmUpsell){
var confirmUpsell = confirm("Would you like to buy any acessories today?");
if (confirmUpsell === true){
var accessoryPrompt1 = confirm("Would you like a fancy screen protector?");
if (accessoryPrompt1 === true){
accessories += SCREEN_PROTECTOR;
}
var accessoryPrompt2 = confirm("Would you like a dongle?");
if (accessoryPrompt2 === true){
accessories += DONGLE;
}
var accessoryPrompt3 = confirm("Would you like a protective case?");
if (accessoryPrompt3 === true){
accessories += CASE;
}
var accessoryPrompt4 = confirm("Would you like a car charger?");
if (accessoryPrompt4 === true){
accessories += CAR_CHARGER;
}
else { accessories = 0;
}
}
}
/*Endlessly buy phones and opt to buy accessories until your bank acocunt no
longer suffices for a phone. Be sure to include an option for being too broke
to buy any phone to begin with.
Determine which phone the user wants and see if they can afford it.
Then check if they can afford accessories.*/
var bankBalance = prompt("Enter your current bank balance.");
whichPhone();
while (whichPhone.chosenPhone < bankBalance){
upsell();
var salePrice = ((chosenPhone + accessories) * TAX_RATE) + (chosenPhone + accessories);
bankBalance -= salePrice;
console.log("You have $" + bankBalance + "remaining.");
}