Basic JS

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Write a JavaScript program to calculate days left until next Christmas.

today=new Date(); const cmas=new Date(today.getFullYear(), 11, 25); if (today.getMonth()==11 && today.getDate()>25) { cmas.setFullYear(cmas.getFullYear()+1); } const one_day=1000*60*60*24; console.log(`${Math.ceil((cmas.getTime()-today.getTime())/(one_day))} days left until Christmas!`); Copy

Write a JavaScript program to find the area of a triangle where lengths of the three of its sides are 5, 6, 7.

var side1 = 5; var side2 = 6; var side3 = 7; var perimeter = (side1 + side2 + side3)/2; var area = Math.sqrt(perimeter*((perimeter-side1)*(perimeter-side2)*(perimeter-side3))); console.log(area);

Write a JavaScript program where the program takes a random integer between 1 to 10, the user is then prompted to input a guess number. If the user input matches with guess number, the program will display a message "Good Work" otherwise display a message "Not matched".

// Get a random integer from 1 to 10 inclusive var num = Math.ceil(Math.random() * 10); var gnum = prompt('Guess the number between 1 and 10 inclusive'); if (gnum == num) alert('Matched'); else alert('Not matched, the number was ' + num);

Write a JavaScript program to find 1st January is being a Sunday between 2014 and 2050.

console.log('--------------------'); for (let year = 2014; year <= 2050; year++) { const d = new Date(year, 0, 1); if ( d.getDay() === 0 ) console.log(`1st January is being a Sunday ${year}`); } console.log('--------------------');

Write a JavaScript program to rotate the string 'w3resource' in right direction by periodically removing one letter from the end of the string and attaching it to the front.

function animate_string(id) { var element = document.getElementById(id); var textNode = element.childNodes[0]; // assuming no other children var text = textNode.data; setInterval(function () { text = text[text.length - 1] + text.substring(0, text.length - 1); textNode.data = text; }, 100); }

Write a JavaScript program to calculate days left until next Christmas. Write a JavaScript program to calculate multiplication and division of two numbers

function multiplyBy() { num1 = document.getElementById("firstNumber").value; num2 = document.getElementById("secondNumber").value; document.getElementById("result").innerHTML = num1 * num2; } function divideBy() { num1 = document.getElementById("firstNumber").value; num2 = document.getElementById("secondNumber").value; document.getElementById("result").innerHTML = num1 / num2; }

Write a JavaScript program to print the contents of the current window.

function print_current_page() { window.print(); }

Write a JavaScript program to display the current day and time in the following format.

var today = new Date(); var day = today.getDay(); var daylist = ["Sunday","Monday","Tuesday","Wednesday ","Thursday","Friday","Saturday"]; console.log("Today is : " + daylist[day] + "."); var hour = today.getHours(); var minute = today.getMinutes(); var second = today.getSeconds(); var prepand = (hour >= 12)? " PM ":" AM "; hour = (hour >= 12)? hour - 12: hour; if (hour===0 && prepand===' PM ') { if (minute===0 && second===0) { hour=12; prepand=' Noon'; } else { hour=12; prepand=' PM'; } } if (hour===0 && prepand===' AM ') { if (minute===0 && second===0) { hour=12; prepand=' Midnight'; } else { hour=12; prepand=' AM'; } } console.log("Current Time : "+hour + prepand + " : " + minute + " : " + second);

Write a JavaScript program to get the current date

var today = new Date(); var dd = today.getDate(); var mm = today.getMonth()+1; var yyyy = today.getFullYear(); if(dd<10) { dd='0'+dd; } if(mm<10) { mm='0'+mm; } today = mm+'-'+dd+'-'+yyyy; console.log(today); today = mm+'/'+dd+'/'+yyyy; console.log(today); today = dd+'-'+mm+'-'+yyyy; console.log(today); today = dd+'/'+mm+'/'+yyyy; console.log(today);

Write a JavaScript program to determine whether a given year is a leap year in the Gregorian calendar.

year = window.prompt("Input a Year : "); x = (year % 100 === 0) ? (year % 400 === 0) : (year % 4 === 0); console.log(x);


संबंधित स्टडी सेट्स

Market segmentation - (Target markets & segmentation)

View Set

CITI Responsible Conduct of Research (RCR) - Basic

View Set

Unit 7 - The Securities Act of 1933 and the Primary Markets Quiz/Test Questions

View Set

Ultrasound examination review: Spleen

View Set

Oregelbundna verb: be, become, begin, break, bring, buy, catch, choose, come, do

View Set

ATI Engage Mental Health RN: Foundations of Mental Health Nursing - Foundational Concepts of Mental Health Nursing

View Set