Javascript - how to get new photo and text displayed for each day of the week
up vote
0
down vote
favorite
I am working on a little Javascript project to get the day of the week displayed. I have that part down, but I would also like to have a photo to also represent each day of the week. Is there a way to utilize both text and a photo together in an array item? I have been searching for a while, and the only examples I can find are to get a random photo app, which is not what I need.
My Day Tracker Project
var d = new Date();
var days = ["Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"];
document.getElementById("demo").innerHTML = days[d.getDay()];
javascript arrays date photo
add a comment |
up vote
0
down vote
favorite
I am working on a little Javascript project to get the day of the week displayed. I have that part down, but I would also like to have a photo to also represent each day of the week. Is there a way to utilize both text and a photo together in an array item? I have been searching for a while, and the only examples I can find are to get a random photo app, which is not what I need.
My Day Tracker Project
var d = new Date();
var days = ["Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"];
document.getElementById("demo").innerHTML = days[d.getDay()];
javascript arrays date photo
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am working on a little Javascript project to get the day of the week displayed. I have that part down, but I would also like to have a photo to also represent each day of the week. Is there a way to utilize both text and a photo together in an array item? I have been searching for a while, and the only examples I can find are to get a random photo app, which is not what I need.
My Day Tracker Project
var d = new Date();
var days = ["Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"];
document.getElementById("demo").innerHTML = days[d.getDay()];
javascript arrays date photo
I am working on a little Javascript project to get the day of the week displayed. I have that part down, but I would also like to have a photo to also represent each day of the week. Is there a way to utilize both text and a photo together in an array item? I have been searching for a while, and the only examples I can find are to get a random photo app, which is not what I need.
My Day Tracker Project
var d = new Date();
var days = ["Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"];
document.getElementById("demo").innerHTML = days[d.getDay()];
javascript arrays date photo
javascript arrays date photo
asked 11 hours ago
Matthew Bert
1
1
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
up vote
0
down vote
Just create a new array for photos:
var photos = [
'https://placeimg.com/640/480/animals',
'https://placeimg.com/640/480/arch',
'https://placeimg.com/640/480/nature',
'https://placeimg.com/640/480/people',
'https://placeimg.com/640/480/tech',
'https://placeimg.com/640/480/any',
'https://placeimg.com/640/480/any'
];
Add an empty image tag:
<img id="image">
Setup the src attribute:
document.getElementById("image").src = photos[d.getDay()];
working code
add a comment |
up vote
0
down vote
You could update your array to look like this:
var days =
[
{name: "Monday", img: "https://image.ibb.co/caPP3V/all.jpg"},
{name: "Tuesday", img: "https://image.ibb.co/btn2OV/dontgrowup.jpg"},
{name: "Wednesday", img: "https://image.ibb.co/kQoHOV/everything-Sux.jpg"},
{name: "Thursday", img: "https://image.ibb.co/c2UP3V/enjoy.jpg"},
{name: "Friday", img: "https://image.ibb.co/ifbFAA/college.jpg.jpg"},
{name: "Saturday", img: "https://image.ibb.co/fe7Yxq/hyper.jpg"},
{name: "Sunday", img: "https://image.ibb.co/dKtj3V/cooltobeyou.jpg"}
]
Then to show the day of the week you will then need to add .name at the end
document.getElementById("demo").innerHTML = days[d.getDay()].name;
To show the image for that day, just create an img in the html
<img id="image">
And you can then update the src of that image in a similar way
document.getElementById("image").src= days[d.getDay()].img;
Hope this helps!
I think it would be simpler if days is an object with{dayname: imageURI}
, and just lower case the day name, otherwise you have to loop over the array to find the right object (or make Sunday the first object in the array). ;-)
– RobG
2 hours ago
add a comment |
up vote
0
down vote
Change your array structure to add a image properties like below.
var days = [
{
day: "day name",
image: "image path"
}
];
Working solution
var d = new Date();
var days = [
{
day: "Sunday",
image:
"http://wearesunday.com/wp-content/uploads/2015/01/sunday-logo.png"
},
{
day: "Monday",
image:
"https://www.monday.vc/assets/share-mondayvc-259d07fc0eb8e761596a059e81111291e487be9fa24579cb49411c22190b3a97.png"
},
{
day: "Tuesday",
image:
"https://goodlucksymbols.com/wp-content/uploads/2016/10/Tuesday-Symbolism.jpg"
},
{
day: "Wednesday",
image:
"https://www.thefactsite.com/wp-content/uploads/2017/07/wednesday-facts.jpg"
},
{
day: "Thursday",
image:
"https://www.thefactsite.com/wp-content/uploads/2017/07/wednesday-facts.jpg"
},
{
day: "Friday",
image:
"https://ihcapetown.com/wp-content/uploads/2018/02/friday-vintage-floral-lettering_23-2147659455.jpg"
},
{
day: "Saturday",
image:
"https://cdn.pixabay.com/photo/2015/04/04/19/29/saturday-706914_960_720.jpg"
}
];
document.getElementById("demo").innerHTML = days[d.getDay()].day;
document.getElementById("container").style.background =
"url('" + days[d.getDay()].image + "') no-repeat center";
html,
body {
margin: 0;
padding: 0;
}
p {
color: red;
font-size: 25px;
text-align: center;
padding: 10px;
background: #fff;
}
.container {
width: 100vw;
height: 100vh;
}
<div class="container" id="container"><p id="demo"></p></div>
Disclaimer: All the images are used here are taken from google images.
add a comment |
up vote
0
down vote
You can get the day name in the host default language using the weekday option of Date.prototype.toLocaleString and setting the language to undefined, e.g.
console.log(new Date().toLocaleString(undefined, {weekday:'long'}));
As others have said, getting the image can be done with an array of 7 image references (indexes 0 to 6) and setting the image based on the day number from getDay.
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Just create a new array for photos:
var photos = [
'https://placeimg.com/640/480/animals',
'https://placeimg.com/640/480/arch',
'https://placeimg.com/640/480/nature',
'https://placeimg.com/640/480/people',
'https://placeimg.com/640/480/tech',
'https://placeimg.com/640/480/any',
'https://placeimg.com/640/480/any'
];
Add an empty image tag:
<img id="image">
Setup the src attribute:
document.getElementById("image").src = photos[d.getDay()];
working code
add a comment |
up vote
0
down vote
Just create a new array for photos:
var photos = [
'https://placeimg.com/640/480/animals',
'https://placeimg.com/640/480/arch',
'https://placeimg.com/640/480/nature',
'https://placeimg.com/640/480/people',
'https://placeimg.com/640/480/tech',
'https://placeimg.com/640/480/any',
'https://placeimg.com/640/480/any'
];
Add an empty image tag:
<img id="image">
Setup the src attribute:
document.getElementById("image").src = photos[d.getDay()];
working code
add a comment |
up vote
0
down vote
up vote
0
down vote
Just create a new array for photos:
var photos = [
'https://placeimg.com/640/480/animals',
'https://placeimg.com/640/480/arch',
'https://placeimg.com/640/480/nature',
'https://placeimg.com/640/480/people',
'https://placeimg.com/640/480/tech',
'https://placeimg.com/640/480/any',
'https://placeimg.com/640/480/any'
];
Add an empty image tag:
<img id="image">
Setup the src attribute:
document.getElementById("image").src = photos[d.getDay()];
working code
Just create a new array for photos:
var photos = [
'https://placeimg.com/640/480/animals',
'https://placeimg.com/640/480/arch',
'https://placeimg.com/640/480/nature',
'https://placeimg.com/640/480/people',
'https://placeimg.com/640/480/tech',
'https://placeimg.com/640/480/any',
'https://placeimg.com/640/480/any'
];
Add an empty image tag:
<img id="image">
Setup the src attribute:
document.getElementById("image").src = photos[d.getDay()];
working code
answered 11 hours ago
Charles Cavalcante
7561819
7561819
add a comment |
add a comment |
up vote
0
down vote
You could update your array to look like this:
var days =
[
{name: "Monday", img: "https://image.ibb.co/caPP3V/all.jpg"},
{name: "Tuesday", img: "https://image.ibb.co/btn2OV/dontgrowup.jpg"},
{name: "Wednesday", img: "https://image.ibb.co/kQoHOV/everything-Sux.jpg"},
{name: "Thursday", img: "https://image.ibb.co/c2UP3V/enjoy.jpg"},
{name: "Friday", img: "https://image.ibb.co/ifbFAA/college.jpg.jpg"},
{name: "Saturday", img: "https://image.ibb.co/fe7Yxq/hyper.jpg"},
{name: "Sunday", img: "https://image.ibb.co/dKtj3V/cooltobeyou.jpg"}
]
Then to show the day of the week you will then need to add .name at the end
document.getElementById("demo").innerHTML = days[d.getDay()].name;
To show the image for that day, just create an img in the html
<img id="image">
And you can then update the src of that image in a similar way
document.getElementById("image").src= days[d.getDay()].img;
Hope this helps!
I think it would be simpler if days is an object with{dayname: imageURI}
, and just lower case the day name, otherwise you have to loop over the array to find the right object (or make Sunday the first object in the array). ;-)
– RobG
2 hours ago
add a comment |
up vote
0
down vote
You could update your array to look like this:
var days =
[
{name: "Monday", img: "https://image.ibb.co/caPP3V/all.jpg"},
{name: "Tuesday", img: "https://image.ibb.co/btn2OV/dontgrowup.jpg"},
{name: "Wednesday", img: "https://image.ibb.co/kQoHOV/everything-Sux.jpg"},
{name: "Thursday", img: "https://image.ibb.co/c2UP3V/enjoy.jpg"},
{name: "Friday", img: "https://image.ibb.co/ifbFAA/college.jpg.jpg"},
{name: "Saturday", img: "https://image.ibb.co/fe7Yxq/hyper.jpg"},
{name: "Sunday", img: "https://image.ibb.co/dKtj3V/cooltobeyou.jpg"}
]
Then to show the day of the week you will then need to add .name at the end
document.getElementById("demo").innerHTML = days[d.getDay()].name;
To show the image for that day, just create an img in the html
<img id="image">
And you can then update the src of that image in a similar way
document.getElementById("image").src= days[d.getDay()].img;
Hope this helps!
I think it would be simpler if days is an object with{dayname: imageURI}
, and just lower case the day name, otherwise you have to loop over the array to find the right object (or make Sunday the first object in the array). ;-)
– RobG
2 hours ago
add a comment |
up vote
0
down vote
up vote
0
down vote
You could update your array to look like this:
var days =
[
{name: "Monday", img: "https://image.ibb.co/caPP3V/all.jpg"},
{name: "Tuesday", img: "https://image.ibb.co/btn2OV/dontgrowup.jpg"},
{name: "Wednesday", img: "https://image.ibb.co/kQoHOV/everything-Sux.jpg"},
{name: "Thursday", img: "https://image.ibb.co/c2UP3V/enjoy.jpg"},
{name: "Friday", img: "https://image.ibb.co/ifbFAA/college.jpg.jpg"},
{name: "Saturday", img: "https://image.ibb.co/fe7Yxq/hyper.jpg"},
{name: "Sunday", img: "https://image.ibb.co/dKtj3V/cooltobeyou.jpg"}
]
Then to show the day of the week you will then need to add .name at the end
document.getElementById("demo").innerHTML = days[d.getDay()].name;
To show the image for that day, just create an img in the html
<img id="image">
And you can then update the src of that image in a similar way
document.getElementById("image").src= days[d.getDay()].img;
Hope this helps!
You could update your array to look like this:
var days =
[
{name: "Monday", img: "https://image.ibb.co/caPP3V/all.jpg"},
{name: "Tuesday", img: "https://image.ibb.co/btn2OV/dontgrowup.jpg"},
{name: "Wednesday", img: "https://image.ibb.co/kQoHOV/everything-Sux.jpg"},
{name: "Thursday", img: "https://image.ibb.co/c2UP3V/enjoy.jpg"},
{name: "Friday", img: "https://image.ibb.co/ifbFAA/college.jpg.jpg"},
{name: "Saturday", img: "https://image.ibb.co/fe7Yxq/hyper.jpg"},
{name: "Sunday", img: "https://image.ibb.co/dKtj3V/cooltobeyou.jpg"}
]
Then to show the day of the week you will then need to add .name at the end
document.getElementById("demo").innerHTML = days[d.getDay()].name;
To show the image for that day, just create an img in the html
<img id="image">
And you can then update the src of that image in a similar way
document.getElementById("image").src= days[d.getDay()].img;
Hope this helps!
answered 11 hours ago
Ryan Walls
11
11
I think it would be simpler if days is an object with{dayname: imageURI}
, and just lower case the day name, otherwise you have to loop over the array to find the right object (or make Sunday the first object in the array). ;-)
– RobG
2 hours ago
add a comment |
I think it would be simpler if days is an object with{dayname: imageURI}
, and just lower case the day name, otherwise you have to loop over the array to find the right object (or make Sunday the first object in the array). ;-)
– RobG
2 hours ago
I think it would be simpler if days is an object with
{dayname: imageURI}
, and just lower case the day name, otherwise you have to loop over the array to find the right object (or make Sunday the first object in the array). ;-)– RobG
2 hours ago
I think it would be simpler if days is an object with
{dayname: imageURI}
, and just lower case the day name, otherwise you have to loop over the array to find the right object (or make Sunday the first object in the array). ;-)– RobG
2 hours ago
add a comment |
up vote
0
down vote
Change your array structure to add a image properties like below.
var days = [
{
day: "day name",
image: "image path"
}
];
Working solution
var d = new Date();
var days = [
{
day: "Sunday",
image:
"http://wearesunday.com/wp-content/uploads/2015/01/sunday-logo.png"
},
{
day: "Monday",
image:
"https://www.monday.vc/assets/share-mondayvc-259d07fc0eb8e761596a059e81111291e487be9fa24579cb49411c22190b3a97.png"
},
{
day: "Tuesday",
image:
"https://goodlucksymbols.com/wp-content/uploads/2016/10/Tuesday-Symbolism.jpg"
},
{
day: "Wednesday",
image:
"https://www.thefactsite.com/wp-content/uploads/2017/07/wednesday-facts.jpg"
},
{
day: "Thursday",
image:
"https://www.thefactsite.com/wp-content/uploads/2017/07/wednesday-facts.jpg"
},
{
day: "Friday",
image:
"https://ihcapetown.com/wp-content/uploads/2018/02/friday-vintage-floral-lettering_23-2147659455.jpg"
},
{
day: "Saturday",
image:
"https://cdn.pixabay.com/photo/2015/04/04/19/29/saturday-706914_960_720.jpg"
}
];
document.getElementById("demo").innerHTML = days[d.getDay()].day;
document.getElementById("container").style.background =
"url('" + days[d.getDay()].image + "') no-repeat center";
html,
body {
margin: 0;
padding: 0;
}
p {
color: red;
font-size: 25px;
text-align: center;
padding: 10px;
background: #fff;
}
.container {
width: 100vw;
height: 100vh;
}
<div class="container" id="container"><p id="demo"></p></div>
Disclaimer: All the images are used here are taken from google images.
add a comment |
up vote
0
down vote
Change your array structure to add a image properties like below.
var days = [
{
day: "day name",
image: "image path"
}
];
Working solution
var d = new Date();
var days = [
{
day: "Sunday",
image:
"http://wearesunday.com/wp-content/uploads/2015/01/sunday-logo.png"
},
{
day: "Monday",
image:
"https://www.monday.vc/assets/share-mondayvc-259d07fc0eb8e761596a059e81111291e487be9fa24579cb49411c22190b3a97.png"
},
{
day: "Tuesday",
image:
"https://goodlucksymbols.com/wp-content/uploads/2016/10/Tuesday-Symbolism.jpg"
},
{
day: "Wednesday",
image:
"https://www.thefactsite.com/wp-content/uploads/2017/07/wednesday-facts.jpg"
},
{
day: "Thursday",
image:
"https://www.thefactsite.com/wp-content/uploads/2017/07/wednesday-facts.jpg"
},
{
day: "Friday",
image:
"https://ihcapetown.com/wp-content/uploads/2018/02/friday-vintage-floral-lettering_23-2147659455.jpg"
},
{
day: "Saturday",
image:
"https://cdn.pixabay.com/photo/2015/04/04/19/29/saturday-706914_960_720.jpg"
}
];
document.getElementById("demo").innerHTML = days[d.getDay()].day;
document.getElementById("container").style.background =
"url('" + days[d.getDay()].image + "') no-repeat center";
html,
body {
margin: 0;
padding: 0;
}
p {
color: red;
font-size: 25px;
text-align: center;
padding: 10px;
background: #fff;
}
.container {
width: 100vw;
height: 100vh;
}
<div class="container" id="container"><p id="demo"></p></div>
Disclaimer: All the images are used here are taken from google images.
add a comment |
up vote
0
down vote
up vote
0
down vote
Change your array structure to add a image properties like below.
var days = [
{
day: "day name",
image: "image path"
}
];
Working solution
var d = new Date();
var days = [
{
day: "Sunday",
image:
"http://wearesunday.com/wp-content/uploads/2015/01/sunday-logo.png"
},
{
day: "Monday",
image:
"https://www.monday.vc/assets/share-mondayvc-259d07fc0eb8e761596a059e81111291e487be9fa24579cb49411c22190b3a97.png"
},
{
day: "Tuesday",
image:
"https://goodlucksymbols.com/wp-content/uploads/2016/10/Tuesday-Symbolism.jpg"
},
{
day: "Wednesday",
image:
"https://www.thefactsite.com/wp-content/uploads/2017/07/wednesday-facts.jpg"
},
{
day: "Thursday",
image:
"https://www.thefactsite.com/wp-content/uploads/2017/07/wednesday-facts.jpg"
},
{
day: "Friday",
image:
"https://ihcapetown.com/wp-content/uploads/2018/02/friday-vintage-floral-lettering_23-2147659455.jpg"
},
{
day: "Saturday",
image:
"https://cdn.pixabay.com/photo/2015/04/04/19/29/saturday-706914_960_720.jpg"
}
];
document.getElementById("demo").innerHTML = days[d.getDay()].day;
document.getElementById("container").style.background =
"url('" + days[d.getDay()].image + "') no-repeat center";
html,
body {
margin: 0;
padding: 0;
}
p {
color: red;
font-size: 25px;
text-align: center;
padding: 10px;
background: #fff;
}
.container {
width: 100vw;
height: 100vh;
}
<div class="container" id="container"><p id="demo"></p></div>
Disclaimer: All the images are used here are taken from google images.
Change your array structure to add a image properties like below.
var days = [
{
day: "day name",
image: "image path"
}
];
Working solution
var d = new Date();
var days = [
{
day: "Sunday",
image:
"http://wearesunday.com/wp-content/uploads/2015/01/sunday-logo.png"
},
{
day: "Monday",
image:
"https://www.monday.vc/assets/share-mondayvc-259d07fc0eb8e761596a059e81111291e487be9fa24579cb49411c22190b3a97.png"
},
{
day: "Tuesday",
image:
"https://goodlucksymbols.com/wp-content/uploads/2016/10/Tuesday-Symbolism.jpg"
},
{
day: "Wednesday",
image:
"https://www.thefactsite.com/wp-content/uploads/2017/07/wednesday-facts.jpg"
},
{
day: "Thursday",
image:
"https://www.thefactsite.com/wp-content/uploads/2017/07/wednesday-facts.jpg"
},
{
day: "Friday",
image:
"https://ihcapetown.com/wp-content/uploads/2018/02/friday-vintage-floral-lettering_23-2147659455.jpg"
},
{
day: "Saturday",
image:
"https://cdn.pixabay.com/photo/2015/04/04/19/29/saturday-706914_960_720.jpg"
}
];
document.getElementById("demo").innerHTML = days[d.getDay()].day;
document.getElementById("container").style.background =
"url('" + days[d.getDay()].image + "') no-repeat center";
html,
body {
margin: 0;
padding: 0;
}
p {
color: red;
font-size: 25px;
text-align: center;
padding: 10px;
background: #fff;
}
.container {
width: 100vw;
height: 100vh;
}
<div class="container" id="container"><p id="demo"></p></div>
Disclaimer: All the images are used here are taken from google images.
var d = new Date();
var days = [
{
day: "Sunday",
image:
"http://wearesunday.com/wp-content/uploads/2015/01/sunday-logo.png"
},
{
day: "Monday",
image:
"https://www.monday.vc/assets/share-mondayvc-259d07fc0eb8e761596a059e81111291e487be9fa24579cb49411c22190b3a97.png"
},
{
day: "Tuesday",
image:
"https://goodlucksymbols.com/wp-content/uploads/2016/10/Tuesday-Symbolism.jpg"
},
{
day: "Wednesday",
image:
"https://www.thefactsite.com/wp-content/uploads/2017/07/wednesday-facts.jpg"
},
{
day: "Thursday",
image:
"https://www.thefactsite.com/wp-content/uploads/2017/07/wednesday-facts.jpg"
},
{
day: "Friday",
image:
"https://ihcapetown.com/wp-content/uploads/2018/02/friday-vintage-floral-lettering_23-2147659455.jpg"
},
{
day: "Saturday",
image:
"https://cdn.pixabay.com/photo/2015/04/04/19/29/saturday-706914_960_720.jpg"
}
];
document.getElementById("demo").innerHTML = days[d.getDay()].day;
document.getElementById("container").style.background =
"url('" + days[d.getDay()].image + "') no-repeat center";
html,
body {
margin: 0;
padding: 0;
}
p {
color: red;
font-size: 25px;
text-align: center;
padding: 10px;
background: #fff;
}
.container {
width: 100vw;
height: 100vh;
}
<div class="container" id="container"><p id="demo"></p></div>
var d = new Date();
var days = [
{
day: "Sunday",
image:
"http://wearesunday.com/wp-content/uploads/2015/01/sunday-logo.png"
},
{
day: "Monday",
image:
"https://www.monday.vc/assets/share-mondayvc-259d07fc0eb8e761596a059e81111291e487be9fa24579cb49411c22190b3a97.png"
},
{
day: "Tuesday",
image:
"https://goodlucksymbols.com/wp-content/uploads/2016/10/Tuesday-Symbolism.jpg"
},
{
day: "Wednesday",
image:
"https://www.thefactsite.com/wp-content/uploads/2017/07/wednesday-facts.jpg"
},
{
day: "Thursday",
image:
"https://www.thefactsite.com/wp-content/uploads/2017/07/wednesday-facts.jpg"
},
{
day: "Friday",
image:
"https://ihcapetown.com/wp-content/uploads/2018/02/friday-vintage-floral-lettering_23-2147659455.jpg"
},
{
day: "Saturday",
image:
"https://cdn.pixabay.com/photo/2015/04/04/19/29/saturday-706914_960_720.jpg"
}
];
document.getElementById("demo").innerHTML = days[d.getDay()].day;
document.getElementById("container").style.background =
"url('" + days[d.getDay()].image + "') no-repeat center";
html,
body {
margin: 0;
padding: 0;
}
p {
color: red;
font-size: 25px;
text-align: center;
padding: 10px;
background: #fff;
}
.container {
width: 100vw;
height: 100vh;
}
<div class="container" id="container"><p id="demo"></p></div>
answered 10 hours ago
Sourav
794
794
add a comment |
add a comment |
up vote
0
down vote
You can get the day name in the host default language using the weekday option of Date.prototype.toLocaleString and setting the language to undefined, e.g.
console.log(new Date().toLocaleString(undefined, {weekday:'long'}));
As others have said, getting the image can be done with an array of 7 image references (indexes 0 to 6) and setting the image based on the day number from getDay.
add a comment |
up vote
0
down vote
You can get the day name in the host default language using the weekday option of Date.prototype.toLocaleString and setting the language to undefined, e.g.
console.log(new Date().toLocaleString(undefined, {weekday:'long'}));
As others have said, getting the image can be done with an array of 7 image references (indexes 0 to 6) and setting the image based on the day number from getDay.
add a comment |
up vote
0
down vote
up vote
0
down vote
You can get the day name in the host default language using the weekday option of Date.prototype.toLocaleString and setting the language to undefined, e.g.
console.log(new Date().toLocaleString(undefined, {weekday:'long'}));
As others have said, getting the image can be done with an array of 7 image references (indexes 0 to 6) and setting the image based on the day number from getDay.
You can get the day name in the host default language using the weekday option of Date.prototype.toLocaleString and setting the language to undefined, e.g.
console.log(new Date().toLocaleString(undefined, {weekday:'long'}));
As others have said, getting the image can be done with an array of 7 image references (indexes 0 to 6) and setting the image based on the day number from getDay.
console.log(new Date().toLocaleString(undefined, {weekday:'long'}));
console.log(new Date().toLocaleString(undefined, {weekday:'long'}));
answered 5 hours ago
RobG
95.5k19101143
95.5k19101143
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53266009%2fjavascript-how-to-get-new-photo-and-text-displayed-for-each-day-of-the-week%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password