You are on page 1of 6

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"));
Var variables can be updated and re-declared within its scope; let variables can be updated but not
re-declared; const variables can neither be updated nor re-declared. They are all hoisted to the top
of their scope. But while var variables are initialized with undefined , let and const variables are not
initialized
The this keyword refers to the current object in a method or constructor. The most common use of
the this keyword is to eliminate the confusion between class attributes and parameters with the
same name (because a class attribute is shadowed by a method or constructor parameter).
JavaScript, an object is a standalone entity, with properties and type.
Constructor is a special function that creates and initializes an object instance of a class. In
JavaScript, a constructor gets called when an object is created using the new keyword. The purpose
of a constructor is to create a new object and set values for any existing object properties.
Functions enable programmers to break down or decompose a problem into smaller chunks, each of
which performs a particular task. Once a function is created, the details of how it works can almost
be forgotten about.
JavaScript has 8 Datatypes : String , Number , Bigint , Boolean , Undefined , Null , Symbol. Object.
Steps to define and call a function –
• Declare the variable
• Define a function with a parameter
• Use the parameter
• Assign the function to a variable
• Call the function with arguments
Ways to declare a function –
aBook = function (){ console. Log(“hello”)}aBook();
function aBook(){console. Log(“hello”)} aBook();
A parameter is the variable listed inside the parentheses in the function definition. An argument is
the value that is sent to the function when it is called.

You might also like