₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,324,984 members, 8,419,823 topics. Date: Thursday, 04 June 2026 at 12:07 AM

Toggle theme

Year As Heading On A Webpage - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingYear As Heading On A Webpage (615 Views)

1 Reply (Go Down)

Year As Heading On A Webpage by baggy4luv(op): 12:08pm On Oct 12, 2022
I want to use current year as heading as my h1.like 2022 verification exercise....then i want the year should be incremnting.
Re: Year As Heading On A Webpage by LTCtech: 12:14pm On Oct 12, 2022
baggy4luv:
I want to use current year as heading as my h1.like 2022 verification exercise....then i want the year should be incremnting.
What programming language?

JS or PHP?
Re: Year As Heading On A Webpage by baggy4luv(op): 12:15pm On Oct 12, 2022
LTCtech:
What programming language?

JS or PHP?
Am a newbie either one
Re: Year As Heading On A Webpage by Nobody: 3:33pm On Oct 12, 2022
baggy4luv:
I want to use current year as heading as my h1.like 2022 verification exercise....then i want the year should be incremnting.
To get the current year in JavaScript, call the new Date() constructor to get a date object and call the getFullYear() method on the result, e.g. new Date(). getFullYear() . The getFullYear method will return a number corresponding to the current year.






culled somewhere online
Re: Year As Heading On A Webpage by LTCtech: 3:58pm On Oct 12, 2022
baggy4luv:
Am a newbie either one
Js

var today = new Date();
var year = today.getFullYear();
console.log(year);
Cheers!
Re: Year As Heading On A Webpage by baggy4luv(op): 4:55pm On Oct 12, 2022
LTCtech:
Js



Cheers!
Can it be used as the heading on a webpage
Re: Year As Heading On A Webpage by LTCtech: 8:15am On Oct 13, 2022
baggy4luv:
Can it be used as the heading on a webpage
Yes. Just do

var today = new Date();
var year = today.getFullYear();
document.title=year+' verification exercise';
or you could get the h1 tag by id and do innerHTML
Re: Year As Heading On A Webpage by truthCoder: 11:56am On Oct 14, 2022
LTCtech:
Js



Cheers!
Replace var with let or const.

var is buggy should not be used in new codes.
Re: Year As Heading On A Webpage by Zabiboy: 8:09pm On Oct 14, 2022
<h1 class="year" > </h1>


<s.cript>
var year = document.querySelector(".year")

year.innerText = new Date().getFullYear()
</s.cript>
Re: Year As Heading On A Webpage by remi1444: 8:37pm On Oct 15, 2022
Zabiboy:
<h1 class="year" > </h1>


<s.cript>
var year = document.querySelector(".year"wink

year.innerText = new Date().getFullYear()
</s.cript>
use let. ES6 has laid var to rest.
1 Reply

How To Style A WebpageHow to Create A Webpage Using Html And Host It Using W3spaceI Need A Webpage And An App.234

Tech Companies In Akure, Ondo State, NigeriaPlz Where Can I Get Hysys 7.3 Or Higher.Fellow Programmers I Need Your Help Please