Skip to content

18m Solution #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 18m
Choose a base branch
from
Open

18m Solution #114

wants to merge 1 commit into from

Conversation

SuperSimpleDev
Copy link
Owner

No description provided.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have noticed that the estimatedDeliveryTime response from the POST /orders does not use isWeekend().

Screenshot from 2025-03-12 14-11-40

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it does not. But the "skipping weekends part" was an exercise. Lesson 15 Exercise 15m.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@a10n-jsd use this code

const matchedOption = findDeliveryOption(order.orderTime, productDetails.estimatedDeliveryTime);
console.log(matchedOption);

let deliveryDate = 'undefined';
if(matchedOption){
       deliveryDate = calculateDeliveryDateFrom(order.orderTime, matchedOption);
}
 <div class="product-quantity">
     Quantity: ${productDetails.quantity}
 </div>
// all this code for skipping weekends from product-delivery-date
// to skip weekends we need deliveryOptions.deliveryDays 
// but the products we get from backend doesnt have deliveryOption, and we cant change backend
// so here is the code for finding an deliveryOption, which we can use in our function

function countDaysBetween(startDate, endDate) {
    // .diff is built-in method of dayjs which calculates tha difference between two dates in days
    return dayjs(endDate).diff(dayjs(startDate), 'day');
}

function findDeliveryOption(orderTime, estimatedDeliveryTime){
    const daysBetween = countDaysBetween(orderTime, estimatedDeliveryTime);
    return deliveryOptions.find(option => option.deliveryDays === daysBetween) || null;
}

Alternate version of calculateDeliveryDate(). Put this code in deliveryOptions.js

export function calculateDeliveryDateFrom(orderTime, deliveryOption){
    let orderDate = dayjs(orderTime);
    let daysAdded = 0;

    while(daysAdded < deliveryOption.deliveryDays){
        orderDate = orderDate.add(1, 'day');

        //skip weekends: 0 = Sunday, 6 = Saturday
        if(orderDate.day() !== 0 && orderDate.day() !== 6){
            daysAdded++;
        }
    }

    return orderDate.format('MMMM D');
}

this calculates not from current date but the day we ordered

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@im-anuj thanks dude!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please tell where do we have to put the code you gave above alternate version of calculatedeliverydate?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can put these code at bottom of deliveryOptions.js file, and then can import in order.js and tracking.js

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if anyone having problems, you can checkout my repo- https://github.com/im-anuj/shopping-site-vanilla
i have done all the assignments and modified it a bit, hope it helps.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks i just put it inside order.js and made it a function so i can export it to tracking.

@ceb07
Copy link

ceb07 commented Jun 27, 2025

how do you guys solve the addToCart quantity problem and also the quantity changes after clicking 'buy again' button ?

@ceb07
Copy link

ceb07 commented Jun 27, 2025

` addToCart(productId){
let matchingItem;

this.cartItems.forEach((cartItem) => {
  if(productId === cartItem.productId){
    matchingItem = cartItem
  }
});

const quantitySelector = document.querySelector(`.js-quantity-selector-${productId}`)
const quantity = Number(quantitySelector.value)

if(matchingItem){
  matchingItem.quantity += quantity
}else{
  this.cartItems.push({
    productId,
    quantity,
    deliveryOptionId: '1'
  })
}

this.saveToStorage()

}`

this is my addToCart code inside the cart Class

@DarKnight594
Copy link

DarKnight594 commented Aug 1, 2025 via email

@im-anuj
Copy link

im-anuj commented Aug 1, 2025

Hey, same thing happened to me recently!
I had uploaded this project, and GitHub disabled the repo saying it violated their trademark policy.

What worked for me:

Renamed the repo (removed "Amazon" from the name)

Added a visible disclaimer (like a alert/popup saying it's just an educational project)

Then I contacted GitHub here: https://support.github.com/contact/reinstatement
They gave me 3 days to fix it and reinstated the repo after that.

Hope this helps!

@DarKnight594
Copy link

DarKnight594 commented Aug 1, 2025 via email

@im-anuj
Copy link

im-anuj commented Aug 1, 2025

No its perfectly fine, you just need to message them that i have made changes , and its a static website it does not collect user's data

@DarKnight594
Copy link

DarKnight594 commented Aug 1, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants