I wanted the month to be like March not 3, please var log = \'<p>This is a messa
ID: 3726486 • Letter: I
Question
I wanted the month to be like March not 3, please
var log = '<p>This is a message in the console log.</p>';
function showCopy() {
var d = new Date();
var year = d.getFullYear();
var month = d.getMonth();
Months= ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var footer = document.getElementsByTagName('footer')[0];
var p = document.createElement('p');
p.innerHTML = '© '+ (month+Months+1)+ ' '+year +' by Abiodun Ogunwomoju. All Rights Reserved.';
footer.appendChild(p);
log += '<p> A paragraph has been added to the footer. </p>';
}
window.onload = showCopy;
Explanation / Answer
Below is the modified code tot the given code. modified part is been in bold text.
<html>
<body>
<script>
var log = '<p>This is a message in the console log.</p>';
function showCopy()
{
var d = new Date();
var year = d.getFullYear();
var month = d.getMonth();
Months= ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var footer = document.getElementsByTagName('footer')[0];
var p = document.createElement('p');
//since Months is an array of months, we can simply use index as month to get the Month as text. Ex: April
p.innerHTML = '© '+ (Months[month])+ ' '+year +' by Abiodun Ogunwomoju. All Rights Reserved.';
footer.appendChild(p);
log += '<p> A paragraph has been added to the footer. </p>';
}
window.onload = showCopy;
</script>
<footer>
</footer>
</body>
</html>
Output:
© March 2018 by Abiodun Ogunwomoju. All Rights Reserved.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.