1
1
1. Write a program in JavaScript to display your subject name and subject instructor name of
current academic semester.
```javascript
console.log("Subject Name: Web Technology Workshop-2");
console.log("Subject Instructor Name: ANIKET(Asst. prof. CSE,ITER)");
```
2. Write a program in JavaScript using function that generates all combination of a string.
(Example string: ‘WTW’ Expected output: W,WT,WTW,T,TW)
```javascript
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"));
```
```javascript
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?
```javascript
function isPalindrome(str) {
return (
str ===
str
.split("")
.reverse()
.join("")
);
}
console.log(isPalindrome("racecar"));
```
5. Create a variable of type string and try to add a number to it. Write a program in JavaScript
using typeof operator to find the data type of the string for this question.
```javascript
let str = "Hello";
str += 123;
console.log(typeof str);
```
6. Write a program in JavaScript using objects to display 5 dictionary words and maps its meaning.
```javascript
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. Write a program in JavaScript by using ternary operator , to check the valid age (valid age is
equal or greater than 18) of driving in INDIA.
```javascript
let age = prompt("Enter your age:");
let validAge = age >= 18 ? true : false;
console.log(validAge);
```
8. Write a function in JavaScript to get the number of occurrences of each letter in specified string.
(take specified string as your name).
```javascript
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"));
```