GithubHelp home page GithubHelp logo

javascript_basics's Introduction

JAVASCRIPT_Basics

Exercise1:Write a JavaScript program to display the current day and time in the following format. Sample Output : Today is : Tuesday. Current time is : 10 PM : 30 : 38

Code:const readline=require('readline-sync');

var date=new Date(); var day=date.getDay(); var daylist=["Sunday","Monday","Tuesday","Thursday","Friday","Saturday"]

var hour= date.getHours(); var min=date.getMinutes(); var sec=date.getSeconds(); var ampm=hour >= 12? 'PM':'AM'; hour=hour>=12?hour-12:hour;

if(hour===0 && min==='PM'){ if(min===0 && sec===0){ hour=12; ampm='noon' } else{ hour=00; ampm="AM"; } }

console.log("Today is:"+daylist[day]); console.log("Current Time: "+ hour + ampm + " : " +min+" : "+sec);

Exercise2:Write a JavaScript program to print the contents of the current window

Code

<title>Print the content of current page</title> <script type="text/javascript"> function printContent(){ window.print(); }
</script>

This is a Practice page

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Print this page

========================================================================= Write a JavaScript program to get the current date.

code: const readline=require('readline-sync'); function dateFormate(){ var date=new Date(); var year=date.getFullYear(); var mon=(1+date.getMonth()).toString().padStart(2,'0'); var day=date.getDate(); day=day>=10? day.toString().padStart(2,'0'):day;

return(day+" / "+mon+" / "+year); };console.log(dateFormate());

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

Code:const readline=require('readline-sync'); function areaTriangle(a,b,c) { //area of triangle with 3 sides=square root of(s(s-a)(s-b)(s-c)) where s=(a+b+c)/2 var area; var s=(a+b+c)/2; return area=Math.sqrt(s*(s-a)(s-b)(s-c));

} console.log(areaTriangle(5,6,7));

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.