0% found this document useful (0 votes)
3 views

css micro

The document provides various JavaScript code examples and explanations, including detecting the running browser, using the prompt method, checking for palindromes, counting vowels, and converting characters to Unicode. It also discusses regular expressions, timing events, and web page protection methods. Each example illustrates a specific functionality or concept in JavaScript programming.

Uploaded by

morekunal680
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

css micro

The document provides various JavaScript code examples and explanations, including detecting the running browser, using the prompt method, checking for palindromes, counting vowels, and converting characters to Unicode. It also discusses regular expressions, timing events, and web page protection methods. Each example illustrates a specific functionality or concept in JavaScript programming.

Uploaded by

morekunal680
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Q.

State the use of dotcent tax in JavaScript with the help of suitable example

In JavaScript, "dotcent tax" likely refers to calculating a sales tax or other


percentage-based tax on a price or value. This is done by multiplying the price
by the tax rate (expressed as a decimal, or "dotcent").
Q. Write a JavaScript that identify running browser

function detectBrowser() {

const userAgent = navigator.userAgent;

if (userAgent.includes("Firefox")) {

return "Mozilla Firefox";

} else if (userAgent.includes("Chrome") || userAgent.includes("Chromium")) {

return "Google Chrome";

} else if (userAgent.includes("Safari")) {

return "Apple Safari";

} else if (userAgent.includes("Opera") || userAgent.includes("OPR")) {

return "Opera";

} else if (userAgent.includes("Edge") || userAgent.includes("Edg")) {

return "Microsoft Edge";

} else if (userAgent.includes("MSIE") || userAgent.includes("Trident")) {

return "Internet Explorer";

} else {

return "Unknown";

const browserName = detectBrowser();

console.log("The browser is: " + browserName);


Q write antics of and explain prompt method in JavaScript with the help of suitable
example

<!DOCTYPE html>

<html lang=”en”>

<head>

<title>Prompt() method</title>

</head>

<body style=”text-align: center”>

<h2>Window prompt() Method</h2>

<button onclick=”geek()”>

Click me!

</button>

<p id=”g”></p>

<script>

Function geek() {

Let doc = prompt(

“Please enter some text”,

“GeeksforGeeks”

);

If (doc != null) {

Document.getElementById(

“g”

).innerHTML =

“Welcome to “ + doc;

}
Q. Write a JavaScript that display all properties of window object explain the code

<!DOCTYPE html>

<html>

<head>

<script language=”JavaScript”>

Function winopen() {

Window.open(https://www.geeksforgeeks.org)

Function showstatus() {

Window.status =

“Opening GeeksforGeeks Home page”;

</script>

</head>

<body onload=”showstatus()”>

<input type=”button” name=”btn”

Value=”Open GeeksforGeeks”

Onclick=”winopen()”>

</body>

</html>
Q. Write a javascript function that check whether passed string is pilndrome or not

// Function that check str is palindrome or not

function check_palindrome(str) {

let j = str.length - 1;

for (let i = 0; i < j / 2; i++) {

let x = str[i];//forward character

let y = str[j - i];//backward character

if (x != y) {

// Return false if string not match

return false;

,,}

// Return true if string is palindrome

return true;

// Function that print output if string is palindrome

function is_palindrome(str)

// Variable that is true if string is palindrome

let ans = check_palindrome(str)

// Condition checking ans is true or not

if (ans == true) {

console.log("passed string is palindrome ");

else {

console.log("passed string not a palindrome");


Q. Wright a JavaScript function to count the number of vowels in a given string

// program to count the number of vowels in a string

Function countVowel(str) {

// find the count of vowels

Const count = str.match(/[aeiou]/gi).length;

// return number of vowels

Return count;

// take input

Const string = prompt(‘Enter a string: ‘);

Const result = countVowel(string);

Console.log(result);
Q. State what is a regular expression explain its meaning with the help of suitable
example

A regular expression (shortened as regex or regexp),[1] sometimes referred to as rational


expression,[2][3] is a sequence of characters that specifies a match pattern in text. Usually
such patterns are used by string-searching algorithms for “find” or “find and replace”
operations on strings, or for input validation. Regular expression techniques are developed
in theoretical computer science and formal language theory.

The concept of regular expressions began in the 1950s, when the American
mathematician Stephen Cole Kleene formalized the concept of a regular language. They
came into common use with Unix text-processing

Q. Write a sentence of and explain use of following method of JavaScript timing


event

1.Set timeout()

The window.setTimeout() method can be written without the window prefix.

The first parameter is a function to be executed.

The second parameter indicates the number of milliseconds before execution.

2.setinterval()

The setInterval() method repeats a given function at every given time-interval.

The window.setInterval() method can be written without the window prefix.

The first parameter is the function to be executed.


Q. develop JavaScript to convert the given character to Unicode and vice Versa

Function charToUnicode(char) {

Return char.charCodeAt(0).toString(16).toUpperCase();

Function unicodeToChar(unicode) {

Return String.fromCharCode(parseInt(unicode, 16));

// Examples

Const character = ‘A’;

Const unicodeValue = charToUnicode(character);

Console.log(`The Unicode of ‘${character}’ is: \\u${unicodeValue}`);

Const unicodeString = ‘0041’;

Const convertedChar = unicodeToChar(unicodeString);

Console.log(`The character of ‘\\u${unicodeString}’ is: ${convertedChar}`)

Const character2 = ‘ ’;

Const unicodeValue2 = charToUnicode(character2);

Console.log(`The Unicode of ‘${character2}’ is: \\u${unicodeValue2}`);

Const unicodeString2 = ‘1F600’;

Const convertedChar2 = unicodeToChar(unicodeString2);

Console.log(`The character of ‘\\u${unicodeString2}’ is: ${convertedChar2}`);

Q. List with of protecting your web page and describe any one of the

To protect your webpage, implement a combination of technical measures, including using


an SSL certificate for secure communication, updating software regularly, and
implementing a Web Application Firewall (WAF).

1.SSL/TLS Certificates:

These certificates encrypt the data transmitted between your website and the user’s
browser, preventing eavesdropping and ensuring secure communication.
2.Keep Software Updated:

Regularly update your operating system, web server software, and any plugins or themes
used on your website to patch security vulnerabilities.

Q. Write a function that user for a colour and uses what they select the background
colour of the new web page opened

<!DOCTYPE html>

<html lang=”en”>

<head>

<meta charset=”UTF-8”>

<meta name=”viewport” content=”width=device-width, initial-scale=1.0”>

<title>Set Background Color</title>

</head>

<body>

<h1>Set Background Color</h1>

<button onclick=”setBackgroundColor()”>Set Background</button>

<script>

Function setBackgroundColor() {

Let color = prompt(“Enter a color (e.g., red, #ff0000):”);

Let newWindow = window.open();

newWindow.document.body.style.backgroundColor = color;

</script>

</body>

You might also like