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

Code

Uploaded by

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

Code

Uploaded by

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

to display your subject name and subject instructor name of current academic semester.

console.log("Subject Name: Web Technology Workshop-2");


console.log("Subject Instructor Name: ANIKET(Asst. prof. CSE,ITER)");

(Example string: ‘WTW’ Expected output: W,WT,WTW,T,TW)

function allCombinations(str) {
let result = [];
let len = str.length;
let power = Math.pow(2, len);
for (let i = 0; i < power; i++) {
let temp = "";
for (let j = 0; j < len; j++) {
if (i & Math.pow(2, j)) {
temp += str[j];
} }
if (temp !== "") {
result.push(temp);
} }
return result.join(",");
}
console.log(allCombinations("WTW"));

3. Write a JavaScript function that reverse a number.

function reverseNumber(num) {
return parseInt(num.toString().split("").reverse().join(""));
}
console.log(reverseNumber(12345));

4. Write a JavaScript function that checks whether a passed string is palindrome or not?

function isPalindrome(str) {
return (
str ===str
.split("")
.reverse()
.join("")
);}
console.log(isPalindrome("racecar"));

5.Write a program in JavaScript using typeof operator

let str = "Hello";


str += 123;
console.log(typeof str);
6. using objects to display 5 dictionary words and maps its meaning.
let dictionary = {
"apple": "a round fruit with red or green skin and firm white flesh",
"banana": "a long curved fruit which grows in clusters",
"cherry": "a small round fruit with a red or black skin and a single hard stone",
"grape": "a small green or purple fruit that grows in bunches",
"orange": "a large round juicy citrus fruit with a tough bright reddish-yellow rind"
};
for (let word in dictionary) {
console.log(word + ": " + dictionary[word]);
}

7.using ternary operator , to check the valid age of driving in INDIA.


let age = prompt("Enter your age:");
let validAge = age >= 18 ? true : false;
console.log(validAge);

8. number of occurrences of each letter in specified string.

function countLetters(str) {
let result = {};
for (let i = 0; i < str.length; i++) {
if (result[str[i]]) {
result[str[i]]++;
} else {
result[str[i]] = 1;
}}
return result;}
console.log(countLetters("Aniket"));

You might also like