Advertisement
weighter

assn p2

Dec 15th, 2021
645
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.73 KB | None | 0 0
  1.  
  2.  
  3. const processReceipt = () =>{
  4.     console.log("processing");
  5.  
  6.     const dublinPlane = 699.99;
  7.     const dublinBoat = 999.99;
  8.     const corkPlane = 599.99;
  9.     const corkBoat = 799.99;
  10.  
  11.     const name = getCookieByName("Name");
  12.     const transportation = getCookieByName("Transportation Choice");
  13.     const city = getCookieByName("City Choice");
  14.  
  15.     console.log(name);
  16.     console.log(transportation);
  17.     console.log(city);
  18.  
  19.     $("[name='name']").val(name);
  20.     $("[name='city']").val(city);
  21.     $("[name='transportation']").val(transportation);
  22.  
  23.     console.log(dublinPlane.toFixed(2))
  24.  
  25.     if( city === "none" || transportation === "none"){
  26.         $("#total-due").val("$0 (Requires City AND Transportation)")
  27.     } else if( city === "Dublin" && transportation === "Plane"){
  28.         $("#total-due").val(dublinPlane.toFixed(2));
  29.     }else if( city === "Dublin" && transportation === "Boat"){
  30.         $("#total-due").val(dublinBoat.toFixed(2));
  31.     }else if( city === "Cork" && transportation === "Plane"){
  32.         $("#total-due").val(corkPlane.toFixed(2));
  33.     }else if( city === "Cork" && transportation === "Boat"){
  34.         $("#total-due").val(corkBoat.toFixed(2));
  35.     }
  36.  
  37.  
  38.  
  39. }
  40.  
  41. const getCookieByName = (name) =>{
  42.  
  43.     const cookies = document.cookie;
  44.  
  45.     let start = cookies.indexOf(name + "=");
  46.  
  47.     if (start === -1){
  48.         return "";
  49.     }else {
  50.         start = start + (name.length +1);
  51.         let end = cookies.indexOf(";", start);
  52.         if (end === -1){
  53.             end = cookies.length;
  54.         }
  55.         const cookieValue = cookies.substring(start,end);
  56.         return decodeURIComponent(cookieValue);
  57.     }
  58. }
  59.  
  60.  
  61.  
  62.  
  63. $(document).ready(
  64.     () => {
  65.  
  66.         processReceipt();
  67.  
  68.  
  69.  
  70.     }
  71. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement