I don't want decimal points like 65 days = 6.2weeks
. I want 65 days = 6 weeks 1 day
I can't use any libraries (not homework)
Assuming Java (I don't know Javascript):
weeks = days / 7;
days_out = days % 7;
Simply use a modulus to get the amounts of days remaining then divide the rest by 7.
var daysLeft = days % 7;
var weeks = Math.floor(days / 7);
The code above works in both Java and JavaScript (remember, other than having "Java" in the name, Java and JavaScript are two different, unrelated languages). It might be more appropriate to declare the variables as an int
in Java however.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With