Posts

Day 100: Date Time to Number of 100DaysCodingChallenge

Image
Hello all,  #day100  Day100  Today's my task was to Write a Program to Convert Date and Time to Number. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  // program to display the date // get local machine date time const date = new Date(); const datetime = Date.now(); // get the date as a string const n = date.toDateString(); // get the time as a string //const time = datetime.toLocalTimeString(); let t = datetime.toString(); let time = date.getTime(); //let dt = time.toLocalTimeString(); // display date console.log('Date: ' + date); // display time //console.log('Time: ' + time); console.log(t); Output :         Happy Coding:)           Day 100 Of 100 Days Coding Challenge Thank you...      

Day 99: Encode String to Base64 Using Object of 100DaysCodingChallenge

Image
Hello all,  #day99  Day99  Today's my task was to Write a Program to Encode a String (input entered by the user) to Base64 using Object. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  const string = prompt("Enter a String : "); // program to encode a string to Base64 // create Base64 Object const Base64 = { // private property _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", // public method for encoding encode: function(input) { let output = ""; let chr1, chr2, chr3, enc1, enc2, enc3, enc4; let i = 0; input = Base64._utf8_encode(input); while (i < input.length) { chr1 = input.charCodeAt(i++); chr2 = input.charCodeAt(i++); chr3 = input.charCodeAt(i++); enc1 = chr1 >> 2; enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); enc4 = chr3 & 6...

Day 98: Compare Two Dates of 100DaysCodingChallenge

Image
Hello all,  #day98  Day98  Today's  my task was to Write a Program to Compare the Two Dates. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  // program to compare value of two dates // create two dates const d1 = new Date(); const d2 = new Date(); console.log(d1); console.log(d2); // comparisons const compare1 = d1 < d2; console.log(compare1); const compare2 = d1 > d2; console.log(compare2); const compare3 = d1 <= d2; console.log(compare3); const compare4 = d1 >= d2; console.log(compare4); const compare5 = d1.getTime() === d2.getTime(); console.log(compare5); const compare6 = d1.getTime() !== d2.getTime(); console.log(compare6); Output :         Happy Coding:) Day 98 Of 100 Days Coding Challenge Thank you...      

Day 97: Format the Date and Time of 100DaysCodingChallenge

Image
Hello all,  #day97  Day97  Today's my task was to Write a Program to Display the Format the Date and Time. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  // program to format the date // get current date let currentDate = new Date(); // get the day from the date let day = currentDate.getDate(); // get the month from the date // + 1 because month starts from 0 let month = currentDate.getMonth() + 1; // get the year from the date let year = currentDate.getFullYear(); // if day is less than 10, add 0 to make consistent format if (day < 10) { day = '0' + day; } // if month is less than 10, add 0 if (month < 10) { month = '0' + month; } // display in various formats const formattedDate1 = month + '/' + day + '/' + year; console.log(formattedDate1); const formattedDate2 = month + '-' + day + '-' + year; console.log(formattedDate2); const formattedDate3 = day + '-' + mo...

Day 96: Current Date and Time of 100DaysCodingChallenge

Image
Hello all,  #day96  Day96  Today's  my task was to Write a Program to Display the Current Date and Time. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  // program to display the date // get local machine date time const date = new Date(); const datetime = Date.now(); // get the date as a string const n = date.toDateString(); // get the time as a string //const time = datetime.toLocaleTimeString(); // display date console.log('Date: ' + n); // display time console.log('Time: ' + datetime); Output :         Happy Coding:) Day 96 Of 100 Days Coding Challenge Thank you...      

Day 95: Date and Time of 100DaysCodingChallenge

Image
Hello all,  #day95  Day95  Today's my task was to Write a Program to Display the Date and Time entered input required by the user. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  // program to display the date and time // get date and time let y = parseInt(prompt("Enter Year : ")); let m = parseInt(prompt("Enter Month : ")); let d = parseInt(prompt("Enter Day : ")); let h = parseInt(prompt("Enter Hour : ")); let min = parseInt(prompt("Enter Minutes : ")); let s = parseInt(prompt("Enter Seconds : ")); //const date = new Date(2017, 2, 12, 9, 25, 30); const date = new Date(y, m, d, h, min, s); // get the date as a string const n = date.toDateString(); // get the time as a string const time = date.toLocaleTimeString(); // display date console.log('Date: ' + n); // display time console.log('Time: ' + time); Output :         Happy Coding:) Day 95 Of 100 Days Cod...

Day 94: Spell Each Digit Using Recursion of 100DaysCodingChallenge

Image
Hello all,  #day94  Day94  Today's my task was to Write a Program to Spell each Digit Separately an input Number n and then have to spell each digit separately. (n is entered by user) using Recursion. Today's my task was to Write a Program to Spell each Digit Separately an input Number n and then have to spell each digit separately. (n is entered by user) using Recursion. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  function spell_num(number) { if (number < 10) // base case. { console.log(number, ""); } else { spell_num(Math.floor(number / 10)); // recursive call. console.log(number % 10, ""); } } //spell_num(567); let n = parseInt(prompt("Enter a Number : ")); spell_num(n); const reduce = (fn, acc, [cur, rest]) => cur === undefined ? acc : reduce(fn, fn(acc, cur), rest); //console.log(reduce((a, b) => a + b, 0, [1, 2, 3, 4, 5, 6, 7, 8, 9])); // 45 Output :     ...

Day 93: Fibonacci Series Using Recursion of 100DaysCodingChallenge

Image
Hello all,  #day93  Day93  Today's my task was to Write a Program to Display Fibonacci Series only last Output Number a Certain Number n (n is entered by user) using Recursion. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  const fibonacci = (n) => (n <= 2 ? 1 : fibonacci(n - 1) + fibonacci(n - 2)); //console.log(fibonacci(10)); // 55 let a = parseInt(prompt("Enter a Number : ")); console.log(fibonacci(a)); Output :         Happy Coding:) Day 93 Of 100 Days Coding Challenge Thank you...      

Day 92: LCM Using Recursion of 100DaysCodingChallenge

Image
Hello all,  #day92  Day92  Today's  my task was to Write a Program to Find LCM of two numbers entered by user using Recursion. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  // Javascript program to find LCM of two numbers // Recursive function to return gcd of a and b function gcd(a, b) { if (b == 0) return a; return gcd(b, a % b); } // Function to return LCM of two numbers function lcm(a, b) { return (a / gcd(a, b)) * b; } // Driver program to test above function // let a = 15, b = 20; let a = prompt("Enter a Number a : "); let b = prompt("Enter a Number b : "); console.log("LCM of " + a + " and " + b + " is " + lcm(a, b)); // This code is Output :         Happy Coding:) Day 92 Of 100 Days Coding Challenge Thank you...      

Day 91: GCD Using Recursion of 100DaysCodingChallenge

Image
Hello all,  #day91  Day91  Today's my task was to Write a Program to Find GCD of two numbers entered by user using Recursion. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  let a = prompt("Enter a : "); let b = prompt("Enter b : "); var gcd = function(a, b) { if (!b) { return a; } return gcd(b, a % b); }; //console.log(gcd(2154, 458)); console.log(gcd(a, b)); Output :         Happy Coding:) Day 91 Of 100 Days Coding Challenge Thank you...      

Day 90: Count Up Using Recursion of 100DaysCodingChallenge

Image
Hello all,  #day90  Day90  Today's task was to write a program that will give a countdown of numbers in ascending order upto to the number 10. lower number input entered by the user. Example: from 1 up to 10. Sample Input: 1 Sample Output: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 here, I have taken another input number randomly from the range of between 1 to 10 by myself. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  let a = prompt("Enter a Number : "); // program to count down numbers to 1 function countUp(number) { // display the number console.log(number); // decrease the number value //const newNumber = number + 1; // base case if (number < 10) { //countDown(newNumber); return countUp(number + 1); } return 0; } //countDown(4); countUp(parseInt(a)); Output :         Happy Coding:) Day 90 Of 100 Days Coding Challenge Thank you...      

Day 89: Factorial Using Recursion of 100DaysCodingChallenge

Image
Hello all,  #day89  Day89  Today's my task was to Write a Program to Find Factorial of a given number N using Recursion. (N is entered by the user). I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  //let a = prompt("Enter a Number : "); // program to find the factorial of a number function factorial(x) { // if number is 0 if (x == 0) { return 1; } // if number is positive else { return x * factorial(x - 1); } } // take input from the user const num = prompt('Enter a positive Number: '); // calling factorial() if num is positive if (num >= 0) { const result = factorial(num); console.log(`The Factorial of ${num} is ${result}`); } else { console.log('Enter a positive Number.'); } function factorial1(n) { if (n >= 1) { return n * factorial(n - 1); } } //console.log(factorial(parseInt(a))); Output :         Happy Coding:) Day 89 Of 100 Days Coding Challen...

Day 88: Sum of Numbers Using Recursion of 100DaysCodingChallenge

Image
Hello all,  #day88  Day88  Today's task was to Write a Program to Find Sum of N Natural Numbers (entered by the user) using Recursion. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  // program to find the sum of natural numbers using recursion function sum(num) { if (num > 0) { return num + sum(num - 1); } else { return num; } } // take input from the user const number = parseInt(prompt('Enter a Positive Number : ')); const result = sum(number); // display the result console.log(`The Sum is ${result}`); Output :         Happy Coding:) Day 88 Of 100 Days Coding Challenge Thank you...      

Day 87: Exponential Using Recursion of 100DaysCodingChallenge

Image
Hello all,  #day87  Day87  Today's task was to write a program that gives the exponential of a given number entered by the user using Recursion. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  let n = prompt("Enter a Number : "); let p = prompt("Enter a Power : "); function exponential(num, power) { if (power == 1) { return num; } else { return num * exponential(num, power - 1); } } //exponential(3,4); console.log(exponential(n, p)); Output :         Happy Coding:) Day 87 Of 100 Days Coding Challenge Thank you...      

Day 86: String Reversal Using Recursion of 100DaysCodingChallenge

Image
Hello all,  #day86  Day86  Today's task was to write a program to reverse a string entered by the user using Recursion. I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  let s = prompt("Enter a String : "); function StringRev(text) { if (text.length == 1) { return text; } else { return text.slice(-1) + StringRev(text.slice(0, -1)); } } //StringRev(“SessionStack”); console.log(StringRev(s)); Output :         Happy Coding:) Day 86 Of 100 Days Coding Challenge Thank you...      

Day 85: Decending Numbers Using Recursion of 100DaysCodingChallenge

Image
Hello all,  #day85  Day85  Today's task was to write a program that will give a countdown of numbers in descending order. higher number input entered by the user. Example: from 10 down to 1. Sample Input: 10 Sample Output: 10,9,8,7,6,5,4,3,2,1 I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  let a = prompt("Enter a Number : "); function descendNum(StartNum) { console.log(StartNum); let NextNum = StartNum - 1; if (NextNum > 0) { descendNum(NextNum); } } //descendNum(10); descendNum(parseInt(a)); Output :         Happy Coding:) Day 85 Of 100 Days Coding Challenge Thank you...      

Day 84: Find Repeated Character From a String of 100DaysCodingChallenge

Image
Hello all,  #day84  Day84  Today's task was to Write a JavaScript program to find the Repeted Character in a given string. Words must be separated by only one space. Example: Sample Input: repeated Sample Output: e I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  // character that is repeated function findRepeatFirstN2(s) { // This is O(N^2) method let p = -1, i, j; for (i = 0; i < s.length; i++) { for (j = i + 1; j < s.length; j++) { if (s[i] == s[j]) { p = i; break; } } if (p != -1) break; } return p; } // Driver code //let str = "geeksforgeeks"; let str = prompt("Enter a String : "); let pos = findRepeatFirstN2(str); if (pos == -1) console.log("Not found"); else console.log(str[pos]); // This code is contributed Output :         Happy Coding:) Day 84 Of 100 Days Coding Challenge Thank you...      

Day 83: Longest Word From a String of 100DaysCodingChallenge

Image
Hello all,  #day83  Day83  Today's task was to Write a JavaScript program to find the largest word in a given string. Words must be separated by only one space. Example: Sample Input: JavaScript code Sample Output: The Largest Word is JavaScript I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  function getLongestWord(str) { let words = str.split(' '); let maxLength = 0; let longestWord = ''; for (let i = 0; i < words.length; i++) { if (words[i].length > maxLength) { maxLength = words[i].length; longestWord = words[i]; } } //console.log(maxLength); console.log("The Longest Word is ", longestWord); } let str = prompt("Enter a String : "); getLongestWord(str); Output :         Happy Coding:) Day 83 Of 100 Days Coding Challenge Thank you...      

Day 82: Capital First Letter of a String of 100DaysCodingChallenge

Image
Hello all,  #day82  Day82  Today's task was to Write a program to capitalize the first letter of each word of a given string. Words must be separated by only one space Example: Sample Input: hardik kotak Sample Output: Hardik Kotak I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  function capital_letter(str) { str = str.split(" "); for (var i = 0, x = str.length; i < x; i++) { str[i] = str[i][0].toUpperCase() + str[i].substr(1); } return str.join(" "); } //console.log(capital_letter("Write a JavaScript program to capitalize the first letter of each word of a given string.")); let str = prompt("Enter a String : "); console.log(capital_letter(str)); Output :         Happy Coding:) Day 82 Of 100 Days Coding Challenge Thank you...      

Day 81: Word Count of a String of 100DaysCodingChallenge

Image
Hello all,  #day81  Day81  Today's task was to Write a program to count all the words in a given string. Words must be separated by only one space Example: Sample Input: hardik kotak Sample Output: number of words : 2 I have started the 100 days of coding  challenge  to improve my programming skills.. Code :  //given input string. var OUT = 0; var IN = 1; // returns number of words in str function countWords( str) { var state = OUT; var wc = 0; // word count var i = 0; // Scan all characters one // by one while (i < str.length) { // If next character is a separator, // set the state as OUT if (str[i] == ' ' || str[i] == '\n'|| str[i] == '\t') state = OUT; // If next character is not a word // separator and state is OUT, then // set the state as IN and increment // word count ...