Assignment
let num = [7, 9, 0, -2];
let n = 3;
// Q1
console.log(num.slice(0, n));
// Q2
console.log(num.slice(-n));
// Q3
let str = prompt("Enter string:");
if (str.length == 0) {
console.log("string is empty");
} else {
console.log("string is not empty");
}
// Q4
let str2 = prompt("enter StRiNg:");
let idx = prompt("enter index:");
if (str2[idx] == str2[idx].toLowerCase()) {
console.log("character is lowercase");
} else {
console.log("character is not lower case");
}
// Q5
let str3 = prompt("enter string with spaces:");
console.log(`String with spaces:${str3}`);
console.log(`string without spaces:${str3.trim()}`);
// Q6
let arr = ["abhi", 122, 4.5, "p"];
let element = 143;
if (arr.indexOf(element) == -1) {
console.log("Element doesn't exist");
} else {
console.log("element exists");
}

Comments
Post a Comment