Advertisement
NewBestPastebins

Gigachad calculator V1

Sep 11th, 2023 (edited)
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. 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"];
  2.  
  3. // Create a string of options separated by newlines
  4. var optionsString = options.join("\n\n");
  5.  
  6. // Show a prompt with the options and ask for a choice
  7. var choice = prompt("Vælg en af de følgende valg muligheder:\n\n" + optionsString);
  8.  
  9. // Convert the choice to a number
  10. var choiceNumber = Number(choice);
  11.  
  12. // Check if the choice is valid
  13. if (choiceNumber >= 1 && choiceNumber <= 20) {
  14. // Execute the code for the chosen option
  15. switch (choiceNumber) {
  16. case 1:
  17. // Ask for a number and a percentage
  18. var number = prompt("Skriv tallet du vil tage en procent af:");
  19. var percentage = prompt("Skriv den procentdel, der skal tages af tallet:");
  20.  
  21. // Calculate the certain percentage of the number
  22. var answer = number * (percentage / 100);
  23.  
  24. // Display the answer in an alert
  25. alert(percentage + "% af " + number + " er: " + answer + ".");
  26.  
  27. break;
  28. case 2:
  29. // Ask for the value of rise in percent and number
  30. var rise = prompt("Skriv stigningen i procent (uden % tegn):");
  31. var number = prompt("Skriv tallet:");
  32.  
  33. // Calculate the original number before the rise
  34. var original = number / (1 + rise / 100);
  35.  
  36. // Display the answer in an alert
  37. alert("Det originale tal er: " + original);
  38.  
  39. break;
  40. case 3:
  41. var currentPrice = prompt("Skriv den nuværende pris på varen:");
  42. var offerPercentage = prompt("Skriv hvor stort tilbudet er i procent (uden % tegn):");
  43.  
  44. // Calculate the original price before the offer
  45. var originalPrice = currentPrice / (1 - offerPercentage / 100);
  46.  
  47. // Calculate the amount of money saved
  48. var moneySaved = originalPrice - currentPrice;
  49.  
  50. // Display the money saved in an alert
  51. alert("Du sparer: " + moneySaved + " på produktet");
  52. break;
  53. // ... and so on for the rest of the options
  54. default:
  55. break;
  56. }
  57. // Show an alert with the chosen option
  58. alert("Du valgte: " + options[choiceNumber - 1]);
  59. } else {
  60. // Show an alert with an invalid choice
  61. alert("Vælg venligst et tal imellem 1 og 20.");
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement