Skip to content

Instantly share code, notes, and snippets.

@badatyajugal89-glitch
Created December 23, 2025 06:26
Show Gist options
  • Select an option

  • Save badatyajugal89-glitch/efdb036f93a267701101262d660be021 to your computer and use it in GitHub Desktop.

Select an option

Save badatyajugal89-glitch/efdb036f93a267701101262d660be021 to your computer and use it in GitHub Desktop.
TASK (11-14)
"TASK-11"
console.log('A' - 1); // NaN
console.log('A' + 1); // "A1"
console.log(2 + '2' + '2'); // "222"
console.log('hello' + 'world' + 89); // "helloworld89"
console.log('hello' - 'world' + 89); // NaN
console.log('hello' + 78); // "hello78"
console.log('78' - 90 + '2'); // "-122"
console.log(2 - '2' + 90); // 90
console.log(89 - '90' / 2); // 44
console.log((true == false) > 2);
" TASK -12"
// 1. extract first five letters
let str1 = " gfuh ieiuei ";
console.log(str1.trim().slice(0, 5)); // "gfuh "
// 2. get length and make uppercase
let str2 = "hduej dij";
console.log(str2.length); // 9
console.log(str2.toUpperCase()); // "HDUEJ DIJ"
// 3. lowercase and trim
let str3 = " biji jdo ";
console.log(str3.toLowerCase().trim()); // "biji jdo"
// 4. replace specified word
let sentence = "I love JS, JS is fun";
console.log(sentence.replace("JS", "JavaScript")); // "I love JavaScript, JS is fun"
// 5. random implicit coercion statement
console.log(89 + "hello" + 90 / 9); // "89hello10"
" TASK-13"
// 1. create an object for animal, car
const animal = {
name: "Dog",
legs: 4,
sound: "Bark"
};
const car = {
brand: "Tesla",
model: "Model 3",
year: 2024
};
// 2. find the duplicate in a string (use array)
const str = "helloworld";
const chars = str.split("");
const duplicates = chars.filter((ch, i, arr) => arr.indexOf(ch) !== i);
console.log([...new Set(duplicates)]);
// 3. reverse a string (use array method)
const original = "javascript";
const reversed = original.split("").reverse().join("");
console.log(reversed); // "tpircsavaj"
// 4. find the highest and lowest value in array
const nums = [5, 12, 3, 45, 7];
const highest = Math.max(...nums);
const lowest = Math.min(...nums);
console.log(highest, lowest); // 45 3
// 5. sorting of an array
const sortedAsc = [...nums].sort((a, b) => a - b);
const sortedDesc = [...nums].sort((a, b) => b - a);
console.log(sortedAsc);
console.log(sortedDesc);
// 6. display first 3 elements in an array in UI (basic example)
const arr = ["one", "two", "three", "four", "five"];
const firstThree = arr.slice(0, 3);
console.log(firstThree); // ["one","two","three"]
// 7. remove 4th (index) element and add 2 elements there
let arr2 = [10, 20, 30, 40, 50, 60];
arr2.splice(4, 1, 70, 80); // remove element at index 4 and add 70, 80
console.log(arr2); // [10,20,30,40,70,80,60]
" TASK-14"
// 1. parameterized method/function to multiply 3 numbers
function multiplyThree(a, b, c) {
return a * b * c;
}
console.log(multiplyThree(2, 3, 4)); // 24
// 2. parameterized method to divide 2 numbers
function divideTwo(a, b) {
return a / b;
}
console.log(divideTwo(10, 2)); // 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment