var options = ["1. Procent af et givent tal (fx. 20% af 100)", "2. Find originale tal efter en stigning (fx. tallet et 120 efter en stigning på 20%, hvad var det originale tal?)", "3. Hvor meget har jeg sparet? (fx. et produkt koster 80kr, fordi der er et tilbud på 20 procent. Hvor meget sparer jeg, hvis jeg køber produktet?)", "option 4", "option 5", "option 6", "option 7", "option 8", "option 9", "option 10", "option 11", "option 12", "option 13", "option 14", "option 15", "option 16", "option 17", "option 18", "option 19", "option 20"];
// Create a string of options separated by newlines
var optionsString = options.join("\n\n");
// Show a prompt with the options and ask for a choice
var choice = prompt("Vælg en af de følgende valg muligheder:\n\n" + optionsString);
// Convert the choice to a number
var choiceNumber = Number(choice);
// Check if the choice is valid
if (choiceNumber >= 1 && choiceNumber <= 20) {
// Execute the code for the chosen option
switch (choiceNumber) {
case 1:
// Ask for a number and a percentage
var number = prompt("Skriv tallet du vil tage en procent af:");
var percentage = prompt("Skriv den procentdel, der skal tages af tallet:");
// Calculate the certain percentage of the number
var answer = number * (percentage / 100);
// Display the answer in an alert
alert(percentage + "% af " + number + " er: " + answer + ".");
break;
case 2:
// Ask for the value of rise in percent and number
var rise = prompt("Skriv stigningen i procent (uden % tegn):");
var number = prompt("Skriv tallet:");
// Calculate the original number before the rise
var original = number / (1 + rise / 100);
// Display the answer in an alert
alert("Det originale tal er: " + original);
break;
case 3:
var currentPrice = prompt("Skriv den nuværende pris på varen:");
var offerPercentage = prompt("Skriv hvor stort tilbudet er i procent (uden % tegn):");
// Calculate the original price before the offer
var originalPrice = currentPrice / (1 - offerPercentage / 100);
// Calculate the amount of money saved
var moneySaved = originalPrice - currentPrice;
// Display the money saved in an alert
alert("Du sparer: " + moneySaved + " på produktet");
break;
// ... and so on for the rest of the options
default:
break;
}
// Show an alert with the chosen option
alert("Du valgte: " + options[choiceNumber - 1]);
} else {
// Show an alert with an invalid choice
alert("Vælg venligst et tal imellem 1 og 20.");
}