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 :         Happ

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...