+ 2

Guys how can I do this in JavaScript???

You and your friends are going to Europe! You have made plans to travel around Europe with your friends, but one thing you need to take into account so that everything goes according to play, is that the format of their date is different than from what is used in the United States. Your job is to convert all your dates from MM/DD/YYYY to DD/MM/YYYY. Task: Create a function that takes in a string containing a date that is in US format, and return a string of the same date converted to EU. Input Format: A string that contains a date formatting 11/19/2019 or November 19, 2019. Output Format: A string of the same date but in a different format: 19/11/2019. Sample Input: 7/26/2019 Sample Output: 26/7/2019 This is my try let date = new Date(prompt()); let month =date.getMonth()+1, day=date.getDay()+1, year=date.getFullYear(); console.log(`${day}/${month}/${year}`) But it doesn't work well donno why

30th Dec 2022, 7:16 AM
Kizito David
Kizito David - avatar
4 Answers
+ 4
// for day you neef to use: let day=date.getDate(); // because that what you have is a weekday
30th Dec 2022, 8:03 AM
JaScript
JaScript - avatar
+ 3
Use date.getDate() instead of date.getDay() +1 for date.
30th Dec 2022, 8:00 AM
Jayakrishna 🇼🇳
+ 2
Ok bro let me try it out
30th Dec 2022, 9:47 AM
Kizito David
Kizito David - avatar
+ 2
Bro it finally came out. Thanks guyz alot
31st Dec 2022, 9:45 AM
Kizito David
Kizito David - avatar