my code is passing all the test in my browser, yet its not passing in my repl and the FCC’s solution link.
3rd day ive been on this now… already tried different codes, same thing.
code:
resObject = {};
app.get('/api/timestamp/:input', (req, res) => {
let input = req.params.input;
if(input.includes('-')){
resObject['unix'] = new Date(input).getTime();
resObject['utc'] = new Date(input).toUTCString();
}else{
input = parseInt(input);
resObject['unix'] = new Date(input).getTime();
resObject['utc'] = new Date(input).toUTCString();
}
if(!resObject['unix'] || !resObject['utc']){
res.json({error: "Invalid Date"})
}
res.json(resObject);
});
app.get('/api/timestamp', (req, res) => {
resObject['unix'] = new Date().getTime();
resObject['utc'] = new Date().toUTCString();
res.json(resObject);
})
When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor ( </> ) to add backticks around text.
i cant believe ive been figuring it out myself (felt like a code guru, only lasted for one sec tho)
so now every other thing is passing except this code
resObject = {};
app.get('/api/:date_string', (req, res) => {
let date_string = req.params.date_string;
if(date_string.includes('-')){
resObject['unix'] = new Date(date_string).getTime();
resObject['utc'] = new Date(date_string).toUTCString();
}else{
date_string = parseInt(date_string);
resObject['unix'] = new Date(date_string).getTime();
resObject['utc'] = new Date(date_string).toUTCString();
}
if(!resObject['unix'] || !resObject['utc']){
res.json({error: "Invalid Date"})
}
res.json(resObject);
});
app.get('/api/', (req, res) => {
resObject['unix'] = new Date().getTime();
resObject['utc'] = new Date().toUTCString();
res.json(resObject);
});
except this part
Your project can handle dates that can be successfully parsed by new Date(date_string)