Professional Documents
Culture Documents
Aim:
To write a script to perform type conversion of values using JavaScript.
Procedure:
Pass a value of String type and convert it to Number type
Pass a Boolean type value and convert it to Number type
Pass a value of Number type and convert it to String type
Pass a Boolean type value and convert it to String type
Pass a value of Number type and convert it to Boolean type
Pass a String type value and convert it to Boolean type
Coding:
String Conversion
let value = true;
alert(typeof value);
value = String(value);
alert(typeof value);
Numeric Conversion
letstr = "123";
alert(typeofstr);
letnum = Number(str);
alert(typeofnum);
BooleanConversion
alert( Boolean(1) );
alert( Boolean(0) );
alert( Boolean("hello"));
alert( Boolean("") );
Result:
Thus the type conversion has been done successfully.
Ex 2: Date, Day and Time functions in JavaScript
Aim:
To write a script to display dates, time and day using JavaScript Date Time
functions.
Procedure:
Get today’s date using Date( ) function
Display the date with arguments such as year, month, day, hours, minutes,
seconds and milliseconds.
Display a date using Date String argument
Coding:
const d1 = new Date( );
document.write(‘Todays date is ’+d1);
// Tue Jan 02 2024 14:19:55 GMT+0530 (India Standard Time)
new Date(year,month,day,hours,minutes,seconds,ms);
const d3 = new Date(2018, 11, 24, 10, 33, 30, 0);
document.write(‘7 arguments:’+d3);
//Mon Dec 24 2018 10:33:30 GMT+0530 (India Standard Time)
new Date(year,month,day,hours,minutes,seconds);
const d4 = new Date(2018, 11, 24, 10, 33, 30);
document.write(‘6 arguments:’+d4);
//Mon Dec 24 2018 10:33:30 GMT+0530 (India Standard Time)
new Date(year,month,day,hours,minutes);
const d5 = new Date(2018, 11, 24, 10, 33);
document.write(‘5 arguments:’+d5);
//Mon Dec 24 2018 10:33:00 GMT+0530 (India Standard Time)
new Date(year,month,day,hours);
const d6 = new Date(2018, 11, 24, 10);
document.write(‘4 arguments:’+d6);
//Mon Dec 24 2018 10:00:00 GMT+0530 (India Standard Time)
new Date(year,month,day);
const d7 = new Date(2018, 11, 24);
document.write(‘3 arguments:’+d7);
//Mon Dec 24 2018 00:00:00 GMT+0530 (India Standard Time)
new Date(year,month);
const d8 = new Date(2018, 11);
document.write(‘2 arguments:’+d8);
//Sat Dec 01 2018 00:00:00 GMT+0530 (India Standard Time)
Result:
Thus the type conversion has been done successfully.
Procedure:
Get any year from the user.
Write a user-defined function to find the given year is leap year or not.
Divide the year by 4.
Determine whether the year is leap year or not using the remainder value.
Coding:
function checkLeapYear(year)
{
if ((year % 4 ==0 ) && (year % 100 !=0 ) || (year % 400 ==0 ))
{
console.log(year + ' is a leap year');
}
else
{
console.log(year + ' is not a leap year');
}
}
const year = prompt('Enter a year:');
checkLeapYear(year);
Result:
Thus the given is either leap year or not has been found successfully.
Procedure:
Generate random number using random( ) function
Display the values along with various operations
Coding:
let x = Math.random();
// Math.random() returns a random number between 0 (inclusive) and 1
(exclusive): 0.19570247303881672
Result:
Thus the random numbers have been generated using built-in function.
Including Bootstrap:
Coding:
<table class="table table-dark">
<thead>
<tr>
<th>S.No</th>
<th>First name</th>
<th>Last name</th>
<th>Handle</th>
</tr>
</thead>
<tbody>
<tr>
<th>1</th>
<td>Seetha</td>
<td>Lakshmi</td>
<td>@slakshmi</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Jacob</td>
<td>Thompson</td>
<td>@jacobt</td>
</tr>
<tr>
<th scope="row">3</th>
<td>Larry</td>
<td>Chris</td>
<td>@chrislarry</td>
</tr>
</tbody>
</table>
Result:
Thus the responsive table has been created and styled using Bootstrap.
Result:
Thus the various styles of buttons have been created using Bootstrap.
Result:
Thus the panels and progress bars have been included using Bootstrap.
Breadcrumbs:
Another form for pagination, is breadcrumbs:
<ul class="breadcrumb">
<li><a href="#">Home</a></li>
<li><a href="#">Private</a></li>
<li><a href="#">Pictures</a></li>
<li class="active">Vacation</li>
</ul>
Result:
Thus the list items have been displayed with pagination using Bootstrap.
Coding:
Result:
Thus the tabs and navigation bars have been included using Bootstrap.
Coding:
Result:
Thus the Glyphicons have been imported into the web page using Bootstrap.
WordPress:
WordPress is an open-source Content Management System.
It is based on PHP and MySql and used to create a dynamic website.
WordPress allows customizing and managing the website from its back-end
content management system.
Usage:
WordPress is widely used for developing
1. E-commerce Websites
2. Educational/Library Websites
3. Personal Websites
Procedure:
HTML Method:
.center-video {
display: block;
margin: 0 auto;
}
Result:
Thus the video has been aligned to centre in WordPress
Procedure:
To create a private post in WordPress, the given steps should be followed.
1. Login to WordPress Dashboard: Enter the username and password to access
the admin area of the WordPress website.
2. Navigate to Posts: On the left-hand side of the dashboard, hover over or click
on "Posts" to expand the menu options.
3. Click on "Add New": From the expanded menu under "Posts," click on "Add
New." The post editor screen will appear.
4. Write the Post: Enter the title and content for the post in the provided fields.
The user can also add media, format text, and customize the post.
5. Set Visibility to Private: In the Publish box on the right-hand side of the
screen, locate the "Visibility" option. Click on the "Edit" link next to it.
6. Choose "Private": In the dropdown menu that appears, select "Private." This
setting ensures that only users with appropriate permissions (typically
administrators and editors) can view the post.
7. Publish or Save Draft: If the private post is ready to publish, click the
"Publish" button.
8. Preview (Optional): The preview option is used to display the preview of the
private post to the user.
Result:
Thus the private post has been created in WordPress