Knowledge Walls
Praveen Kumar R
Finding even and odd days and dates in Basics of JS learning
265 Views
finding odd or even days and dates
	
		<!DOCTYPE html>
	
		<head>
	
		<title> learning date and finding whether the day is odd or even</title>
	
		</head>
	
		<h1> Find whether the day is odd or even </h1>
	
		<p id="demo"> </p>
	
		<label> Enter day </label>
	
		<input type="date" id="myDay"><br><br>
	
		<button type="button" onclick="printDay()">Find oddEven day</button> <br><br>
	
		<label> Enter date </label>
	
		<input type="date" id="myDate"><br><br>
	
		<button type="button" onclick="printDate()">Find oddEven date</button>
	
	
		<script>
	
		function printDay(){
	
		var myDay = document.getElementById('myDay').value;
	
		var p = new Date(myDay);
	
		var newDay = p.getDay();
	
		console.log(newDay);
	
	
		if (newDay %2 == 0){
	
		console.log("it is a even day");
	
		}else{
	
		console.log("it is an odd day");
	
		}
	
		}
	
	
		function printDate(){
	
		var myDate = document.getElementById('myDate').value;
	
		var dt = new Date(myDate);
	
		var newDate = dt.getDate();
	
		console.log(newDate);
	
	
		if (newDate%2 == 0){
	
		console.log("it is a even date");
	
		}else{
	
		console.log("it is an odd date");
	
		}
	
		}
	
	
	
	
		</script>
	
		</html>
Next
Next Topics
Next lessons of current book.
Best Lessons of "JS learning"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details