i am trying to make a component on React JS for displaying different images depend on the time of the day, but i don't get why the image doesn't show up.
This is the code i made:
import React from 'react';
import image1 from "path";
import image2 from "path";
var date = new Date();
var hour = date.getHours();`
var image;
if (hour < 20 && hour > 6) {
image = { image1 };
} else {
image = { image2 };
}
const Body = () => {
return (
<img src={image} alt="image" />
);
};
export default Body;
I would really appreciate your help!!
This is how its done.If anyone ever needs it!
import React from 'react';
import image1 from "path";
import image2 from "path";
var date = new Date();
var hour = date.getHours();`
var image;
if (hour < 20 && hour > 6) {
image = image1 ;
} else {
image = image2 ;
}
const Body = () => {
return (
<img src={image} alt="image" />
);
};
export default Body;