Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,201 members, 7,818,671 topics. Date: Sunday, 05 May 2024 at 09:34 PM

Year As Heading On A Webpage - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Year As Heading On A Webpage (455 Views)

How To Style A Webpage / How to Create A Webpage Using Html And Host It Using W3space / I Need A Webpage And An App. (2) (3) (4)

(1) (Reply) (Go Down)

Year As Heading On A Webpage by baggy4luv(m): 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(m): 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(m): 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.

1 Like 1 Share

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>

1 Like

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 Like

(1) (Reply)

Who Is Using Sololearn For Programming? / Please Check Out My Portfolio / Learn How You Can Set Up Your Own Personal Blog

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 13
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.