├── LICENSE ├── README.md ├── anagram.js ├── check.js ├── closure.js ├── object.js ├── palindrome.js ├── reverse.js ├── strings.js ├── style.js ├── sumofarray.js └── sumofelements.js /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Valentine Fernandes 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > Javascript-Coding-Questions 2 | 3 | 1. Reverse a given string using JavaScript? 4 | 2. Find the sum of all elements/numbers of a given array? 5 | 3. How can we create an object in JS? 6 | 4. How to get the status of a CheckBox ? 7 | 5. How to explain closures in JavaScript and when to use it ? 8 | 6. How can style/class of an element be changed ? 9 | 7. Given two strings, return true if they are anagrams of one another. Write code. 10 | 8. Write code to convert an array of strings to an array of the lengths of those strings. 11 | 9. Write code to sum an array of numbers. 12 | 10. Write a simple function that returns a boolean indicating whether or not a string is a palindrome. 13 | -------------------------------------------------------------------------------- /anagram.js: -------------------------------------------------------------------------------- 1 | var firstWord = "Mary"; 2 | var secondWord = "Army"; 3 | isAnagram(firstWord, secondWord); // true 4 | function isAnagram(first, second) { 5 | // For case insensitivity, change both words to lowercase. 6 | var a = first.toLowerCase(); 7 | var b = second.toLowerCase(); 8 | // Sort the strings, and join the resulting array to a string. Compare the results 9 | a = a.split("").sort().join(""); 10 | b = b.split("").sort().join(""); 11 | return a === b; 12 | } 13 | -------------------------------------------------------------------------------- /check.js: -------------------------------------------------------------------------------- 1 | document.getElementById("Hello").checked; 2 | -------------------------------------------------------------------------------- /closure.js: -------------------------------------------------------------------------------- 1 | //code 2 | function foo() { 3 | var b = 1; 4 | function inner() { 5 | return b; 6 | } 7 | return inner; 8 | } 9 | var get_func_inner = foo(); 10 | 11 | console.log(get_func_inner()); 12 | console.log(get_func_inner()); 13 | console.log(get_func_inner()); 14 | -------------------------------------------------------------------------------- /object.js: -------------------------------------------------------------------------------- 1 | var object = 2 | { 3 | name: "obj", 4 | age: 10 5 | }; 6 | -------------------------------------------------------------------------------- /palindrome.js: -------------------------------------------------------------------------------- 1 | function isPalindrome(str) { 2 | str = str.replace(/\W/g, '').toLowerCase(); 3 | return (str == str.split('').reverse().join('')); 4 | } 5 | -------------------------------------------------------------------------------- /reverse.js: -------------------------------------------------------------------------------- 1 | var str = "Front End Tutorials"; 2 | var output = str 3 | .split("") 4 | .reverse() 5 | .join(""); 6 | document.write(output); 7 | -------------------------------------------------------------------------------- /strings.js: -------------------------------------------------------------------------------- 1 | var words = ["the", "quick", "brown", "fox"]; 2 | var wordLengths = words.map(word => word.length); 3 | // wordLengths = [3, 5, 5, 3] 4 | -------------------------------------------------------------------------------- /style.js: -------------------------------------------------------------------------------- 1 | document.getElementById("myText").style.fontSize = "16px; 2 | 3 | document.getElementById("myText").className = "class"; 4 | -------------------------------------------------------------------------------- /sumofarray.js: -------------------------------------------------------------------------------- 1 | const nums = [1, 2, 3, 4, 5]; 2 | const summer = (a, b) => a + b; 3 | const sum = nums.reduce(summer, 0); 4 | -------------------------------------------------------------------------------- /sumofelements.js: -------------------------------------------------------------------------------- 1 | var arr = [1, 2, 5, 10, 20]; 2 | var sum = 0; 3 | for (let i in arr) { 4 | sum += arr[i]; 5 | } 6 | document.write(sum); 7 | --------------------------------------------------------------------------------