// // // let str1="Hello, "; // // let str2="world"; // // let result=str1+str2; // // console.log(result); // Output: "Hello, world!" // // let firstname="Toufeeque "; // let lastname="Sayyed"; // let fullname=fisrtname + lastname; // console.log(fullname); // let Fisrtname = "Toufeeque"; // let Lastname = "Sayyed"; // let fullname = Fisrtname + " " + Lastname; // console.log(fullname); // Output: "Toufeeque Sayyed" // // let str1 = "Hello, "; // let str2 = "world!"; // let result = str1.concat(str2); // console.log(result); // Output: "Hello, world!" // let str1 = "Hello, "; // let str2 = "world!"; // let result = [str1,str2].join(" "); // console.log(result); // Output: "Hello, world!" // let str1 = "Hello, "; // let str2 = "world!"; // let result = String(str1) + String(str2); // console.log(result); // Output: "Hello, world!" // let str1 = "Hello, "; // let str2 = "world!"; // let result = `$str1}${str2} ${2*3+4} ${"Jaanu"}`; // console.log(result); // Output: "Hello, world!" // Explicit Conversion // let value = 123; // console.log(typeof value) // let strValue = value + ""; // console.log(strValue); // Output: "" // console.log(strValue, typeof strValue); // Output: "string" //1. Number // let a="10.12345"; // let num=parseInt(a); // console.log(num, typeof num); // let b=10.12345; // let num1=b+""; // console.log(num1, typeof num1); // let str="10.123456"; // let num2=parseInt(str); // console.log(num2, typeof num2); //Floating String to Number // let str = "10.12345"; // let floatNum = parseFloat(str); // console.log(floatNum); // Output: 10.12345 // console.log(typeof floatNum); // Output: "number" // Length // let name="My Name Is Toufeeque"; // console.log(name.length); // let name = "toufeeque"; // let upperCaseName = name.toUpperCase(); // console.log(upperCaseName); // Output: TOUFEEQUE // let name1 = "toufeeque"; // let lowerCaseName = name1.toLowerCase(); // console.log(lowerCaseName); // Output: toufeeque // let name = "toufeeque"; // Accessing characters at different positions using charAt method // for (let i = 0; i < name.length; i++) { // console.log(name.charAt(i)); // Output: t, o, u, f, e, e, q, u, e // } // console.log("from script file"); // let a="Toufeeque"; // console.log(a.charAt(0)); // console.log(a.charAt(1)); // console.log(a.charAt(2)); // console.log(a.charAt(3)); // console.log(a.charAt(4)); // console.log(a.charAt(5)); // console.log(a.charAt(6)); // console.log(a.charAt(7)); // console.log(a.charAt(8)); // console.log(a.charAt(9)); // let myage=29; // if (myage=>+18);{console.log("Great")} // let Student = 29; // if (Student <= 30) { // console.log("Your Age is"${Student}"Eligible"); // Output: Good morning! // } else { // console.log("Not Eligible"); // Output: Good afternoon! // } // >=(Greater Than Equal to) {Isse Bada Ya Iske Barabar} Tab Use Karte // Hain Jab Hume Atleast // Humari Requirment Ya Ussay Zyada Chahiye // > Sirf Tab Use Karte Hain Jab Hume Humari Requirment Se Zydada // Hi Chahiye Kam Nahi Chalega // <= (Lessthan Equal to) {Isse Chhota Ya Iske Barabar} // < Lessthan Tab Use Karte Hain Jab Humein Isse Kamhi Chahiye // let Student=18; // if(Student>=18*30) // {console.log(`Your Age is ${Student} You Are Eligible ` // );} // else // // // // // // // // // // {console.log(`Your Under ${Student} Not Eligible`)}; // // // // // // // // // // let a=18 // // // // // // // // // // let y=a*30 // // // // // // // // // // console.log(y); // // // // // // // // // // let num = 10; // // // // // // // // // // // if(num % 2 === 0); // // // // // // // // // // // {console.log(`The ${num} Number Is Even`); // // // // // // // // // // // } else { // // // // // // // // // // // console.log(`The Number ${num} Is Odd`); // // // // // // // // // // // } // // // // // // // // // // // let number = 7; // यहां आप अपनी संख्या डाल सकते हैं // // // // // // // // // // // if (number % 2 === 0); // // // // // // // // // // // {console.log(`${number} is even.`); // // // // // // // // // // // } else { // // // // // // // // // // // console.log(`${number} is odd.`); // // // // // // // // // // // } // // // // // // // // let number = 11; // // // // // // // // if (number%2==0) // // // // // // // // { // // // // // // // // console.log("even."); // // // // // // // // } else { // // // // // // // // console.log("odd"); // // // // // // // // } // // // // // // // // let Score=70; // // // // // // // // if(Score>50) // // // // // // // // {console.log(`Good You Have Passed by ${Score} Percent`)} // // // // // // // // else{console.log(`Oho You Are Failed by ${Score} Percent`);} // // // // // // // const readline = require('readline'); // // // // // // // const rl = readline.createInterface({ // // // // // // // input: process.stdin, // // // // // // // output: process.stdout // // // // // // // }); // // // // // // // rl.on('line', (input) => { // // // // // // // const [A, B] = input.split(' ').map(Number); // // // // // // // // Calculate LHS // // // // // // // const LHS = Math.pow(A + B, 3); // // // // // // // // Calculate RHS // // // // // // // const RHS = Math.pow(A, 3) + Math.pow(B, 3) + 3 * A * A * B + 3 * A * B * B; // // // // // // // // Print LHS and RHS // // // // // // // console.log(LHS); // // // // // // // console.log(RHS); // // // // // // // // Compare LHS and RHS // // // // // // // if (LHS === RHS) { // // // // // // // console.log("VERIFIED"); // // // // // // // } else { // // // // // // // console.log("NOT VERIFIED"); // // // // // // // } // // // // // // // rl.close(); // // // // // // // }); // // // // // // // 1. Positive, Nagative, Or Zero // // // // // // // Quetion : Write a Program to Check Number Is Positive, Nagative, Or Zero // // // // // // let num=10; // // // // // // if(num>0); // // // // // // {console.log("The Number is Positive")} // // // // // // else(num<0); // // // // // // {console.log("Number Is Nagative")} // // // // // // else(num=0); // // // // // // {console.log("Number is Zero");} // // // // // let num=35; // // // // // if(num>=90 && num<=100) // // // // // { // // // // // console.log(`As ${num} Grade A`); // // // // // } // // // // // else if(num>=70 && num>=80) // // // // // { // // // // // console.log(`As ${num} Grade B`); // // // // // } // // // // // else if(num>=50 && num<=70) // // // // // { // // // // // console.log(`As ${num} Grade C`); // // // // // } // // // // // else if(num>35){ // // // // // console.log(`As ${num} You Passed`) // // // // // } // // // // // else{ // // // // // console.log(`As ${num} You Are Failed`); // // // // // } // // // // // // let num = 71; // // // // // // if (num >= 90) { // // // // // // console.log(`As ${num} Grade A`); // // // // // // } else if (num >= 70) { // // // // // // console.log(`As ${num} Grade B`); // // // // // // } else if (num >= 50) { // // // // // // console.log(`As ${num} Grade C`); // // // // // // } else { // // // // // // console.log(`As ${num} Grade D`); // // // // // // } // // // // // let result=20; // // // // #Table // // // let a=2 // // // let b=1 // // // let result=0 // // // for(i=0;i<10;i++){ // // // result=result+a*b // // // console.log(result) // // // } // // // // let profit=5 // // // // let expence=4 // // // // while(profit<expence);{ // // // // console.log(profit+expence); // // // // } // // // // let expence=2; // // // // let profit=2; // // // // let buisness=3; // // // // while(buisness<0){ // // // // expence=expence*profit; // Table(Pahade Likhne Ke Kaam Aata Hai) // // // // buisness--; // // // // console.log(expence) // // // // } // // let base=5; // // let exponent=5; // // let result=; // Yaha Humne result Ki Value 1 Isiliye // // // Rakhi Rakhi Hain Kyunke Hume Multiply Karna Hai 0 Rakhenge // // // Toh output Har Baar 0 Hi Aayega Ha lekin Addition Karna Hota // // // Toh 0 Sahi Hota // // while(exponent>0){ // // result=result*base; // Table(Pahade Likhne Ke Kaam Aata Hai) // // exponent--; // // console.log(result) // // } // // // exponent-- Ka Matlab Hai Ke exponent Ghatta jaye Aur // // // Kyunke Humne Condition Lagai Hai exponent Jab 0 Hojaye Toh // // // Loop Rukjaye Isiliye 5X5 utna Hi Chalega Jitni exponent Ki // // // Value Hogi // // Write your code here // // let sum=0; // // let n=123456789 // Yaha Jo Bhi Digit Hoga Woh Sum Hoga 1+5=6 // // while(n>0){ // // let temp=n%10; // // sum+=temp; // // n=Math.floor(n/10); // // }console.log(sum); // function digitalRoot(n) {// Yaha(n) Jo Bhi Digit Hoga Woh Sum // //Hoga 1+5=6 // let sum = 0; // while (n > 0) // Jab tak n 0 se bada hai, loop chalti rahegi // { // let temp = n % 10; // n ka last digit nikal rahe hain // sum += temp; // temp ko sum mein add kar rahe hain. // n = Math.floor(n / 10); //n ko 10 se divide karke uska // // floor value nikal rahe hain, taaki last digit remove ho jaye. // } // return sum; // } // let number = 12345; // Is Variable Ko (n) Ko Value Dene Ke Liye // // Banaya Gaya Hai // let result = digitalRoot(number); // Yaha digitalRoot Ki Value Ka // // Data type Define Kiya Gaya Hai // while (result >= 10) // result Jab 10 Se Zyada Ya Barabar Ho // { // result = digitalRoot(result); // // Pure Isme Kuch Samjh nahi Aaya Hai Asume Kiya Hai Maine // } // console.log("Digital Root:", result); // let n=123456 // let newnum=0; // while(n>0) // Jab tak n 0 se bada hai, loop chalti rahegi // { // temp=n%2; //Yaha n Yani 123456 Ko 10 Se Devide Kiya Hai // // 123456/10=12345.6 Floating intiger hoga // console.log(n) // Ye Isliye Hai Taaki Loop Se Pahele Print Ho // // Warna Actaul Loop Toh 12345 Se Start Hoga // newnum=newnum*10 + temp; // n=Math.floor(n/10); // Math.floor Use Karne Se Floating Int // // Se Value Noramal Number Hojatati Hai // } // Isiko Reverse Karne Keliye // let n = 123456; // Original number // let reversedNumber = 0; // To store the reversed number // while (n > 0) { // let digit = n % 10; // Extract the last digit // reversedNumber = reversedNumber * 10 + digit; // Append digit to reversedNumber // n = Math.floor(n / 10); // Remove the last digit from n // } // console.log(reversedNumber); // Output the reversed number // let n1=123456 // while(n1>0){ // console.log(n1) // n=n%10; // n=Math.floor(n/10); // } // let count=20 // let a=2 // let b=1 // let result=0 // for(i=0;i<10;i++){ // result=result+a*b; // console.log(result) // let number=[1,2,3,4,6,5,6,7,6,6,8]; // let count=0 // For Loop Ka Logic // i=0;(index=0) Yaha Se Loop Start Hoga Agar "i" Ki Value 1 Karde Toh // Loop Index Ki 2nd Value Se Start Hoga Jo Hume List Ke 1st Word Yani // Value Ko Hatane Mein Kaam Aata Hai // i<number.length; Loop 0 Start Hone Ke Baad Kaha Tak jayega // "i" Ki Jo Bhi position Hogi Waha Se Last Value Tak jayega // Agar Hum number.length-1 Karde Toh List Ki Last Value // Print Nahi Hogi // i++ Ye Kuch Aisa Hai Jaise Humne i=0 Se Soch Liya Yaha Se // Nikalna Hai Begening Point 0 Hoga Aur i<number.length Se Soch // Liya Ke Kaha Tak Jana Hai Ab Bas Engine Start Karna Hai Jo i++ // Se Hoga i++ Loop Ko Aage Badhata Hai Isi Se Loop Chalna // Start Karta Hai // for(i=1;i<number.length;i++){ // if(number[i]==6){ // count++; // } // } // console.log(count); // Isko Curly Bracket Ke Andar Rakhenge Toh Loop // Mein Aajayega isliye Jab Single Output Chahiye Toh Loop // Se Bahar Likhte Hain // * Subarray --------- // function printSubarray(arr) { // for (let start = 0; start < arr.length; start++) { // let tempArray = []; // for (let end = start; end < arr.length; end++) { // tempArray.push(arr[end]); // console.log(tempArray); // } // } // } // Ye Logic Array Ke Jis Index Se Start Hota Hai Waha Se Last Index Tak Jitni Bhi Length // Hogi Utne Subarray Banata Jayega Subarray Usi Ko Kahete Hain Agar Index Ki Length // Total 10 Hai Toh 0 Index Yani First position Wale Index Se 9th position Wale Index Tak // Total 10 Subarray Banege Usi Tarha 1st Index Yani 2nd position Wake Index Ke 9 Index // Banege // End Wala Index Sirf Ek Hi Subarray Banayega Kyunki Uske Aage Koi Aur Element Nahi Hai // let arr3 = [1, 2, 3, 4, 5]; // printSubarray(tempArray); // Objects // let Person= { // FirstName:"Toufeeque", // LastName:"Sayyed", // Age:29, // Address:"Pune", // Skills : ["Driving", "Frontend", "Backend", "Ethical Hacking"]} // console.log(Person.Address); // console.log(Person.Age); //Array // let fruits=["Apple", "Banana", "Cherry", "Mango"]; // console.log(fruits); // //Accessing an Element from an Array // console.log(fruits[0]); // 0 Yani Array Ke Index Ki 1st Position // console.log(fruits[1]); // 1 Yani 2nd Position // console.log(fruits [2]); // 2 Yani 3rd Position // Modifiying an Array // let fruits=["Apple", "Banana", "Cherry", "Mango"] // console.log(fruits); // fruits[0]="Kiwi"; // fruits[1]="Lichi"; // fruits[2]="Dragonfruit"; // fruits[3]="Orange"; // console.log(fruits); // Adding Element in an Array // 1. Specific Index Ki Position Pe Element Daalna // let fruits=["Apple", "Banana", "Cherry", "Mango"] // console.log(fruits); // fruits.splice(1,0"Pineapple") // console.log(fruits); // fruits.splice(0,1 "Orange") // console.log(fruits); // Splice Method Mein Hume fruits.splice(Jis Index Position Pe // Element Ko Rakhna Hai Woh Hum 0 Denge Toh 1st Index Pe Add // Add Hoga, Aur Coma Ke Baad Jo Digit Denge Ussay Jo e // Remove Honge) // Splice Mothod Ka Formula // array.splice(start, deleteCount, item1, item2, ..., itemN) // fruits.splice(0, 1, "Pineapple"); // fruits.splice(0, 0, "Pineapple"); // console.log(fruits) // let fruits=["Apple", "Banana",]; // console.log(fruits) // fruits.splice(1, 0, "Pineapple"); // console.log(fruits); // Manlo Koi Name Galat Hogaya Hai Ya Price Kam Hogaya Hai Usko Change // Karne Ke Liye map Method Use Hota Hai But Sirf Ek Baar Mein Ek Hi Value // Find and Replace Karsakte Hain // (Finding Single Value Multiple Times & Replacing Them) // let updatedFruits = fruits.map(fruit => fruit === // "Banana" ? "Orange" : fruit); // console.log(updatedFruits) // length Method Sirf Single Value Array Ke Last Mein Add Hogi*** // fruits[fruits.length] = "Cherry", "Lichi"; // console.log(fruits); // concat Method ****** // let moreFruits = ["Kiwi", "Mango"]; // let fruits1 = ["Watermelon", "Guava"] // let combinedFruits = fruits.concat(moreFruits, fruits1); // console.log(combinedFruits) // Spread Operators Method ********** // let moreFruits = ["Cherry", "Mango"]; // let fruits1 = ["Guava", "Lichi"] // let combinedFruits = [...fruits, ...moreFruits, ...fruits1]; // console.log(combinedFruits) // let month = 13 // if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { // days = 31; // } else if (month == 4 || month == 6 || month == 9 || month == 11) { // days = 30; // } else if (month == 2) { // days = 28; // } else { // days = "Invalid month"; // } // console.log(days); // let n = 29 // if(n<=28){ // console.log("i am young"); // } // else {console.log("i am not young")} // const readline = require('readline'); // const rl = readline.createInterface({ // input: process.stdin, // output: process.stdout // }); // function bigLight(h1, h2, v1, v2) { // if (v1 === v2) { // return h1 === h2; // } // let difference = h1 - h2; // let speed_difference = v2 - v1; // if (difference % speed_difference === 0 && difference / speed_difference >= 0) { // return true; // } else { // return false; // } // } // rl.on('line', (input) => { // const [h1, h2, v1, v2] = input.split(' ').map(Number); // console.log(bigLight(h1, h2, v1, v2)); // }); // const readline = require('readline').createInterface({ // input: process.stdin, // output: process.stdout // }); // readline.question('', year => { // //Write your code here and print the required output // if((year % 4 == 0 && year % 100 !== 0) || year % 400 == 0){ // console.log(1); // } else { // console.log(0); // } // readline.close(); // }); // let a=5 // let b=8 // function power(a, b) { // let result = 1; // for (let i = 0; i < b; i++) { // result *= a; // } // return result; // } // const result = power(a, b); // console.log(result); // function greet(xyz){ // console.log(`Hello ${xyz}`) // console.log(`Nice to Meet You ${xyz}`) // } // greet(25) // for (i = 1; i <= 5; i++) { // let result = ""; // for (j = 1; j <= i; j++) { // result += j + " "; // } // console.log(result.trim()); // } // let n=4 // for(row = 1; row <= n; row++){ // let result = " "; // for(col = 1; col <= row; col++){ // result += n.length(n) + "* "; // } // console.log(result) // } // let num = 46685; // let digits = 5; // let sum = 0; // for(let i =0; i <= digits; i++){ // let temp=num%10; //Ye % Kisi Bhi Number Ko Devide Karke Aakhri Ka Digit // // Leta Hai Yani Decimal Wala Part // sum+=temp; // num=Math.floor(num/10); // Ye / Kisi Bhi Number Ko Devide Karke Fist Ke Digit // //Yani Starting Wala Part // } // console.log(sum); // let num = 46685 // let sum = 0; // for(let i =0; i <= num; i++){ // sum+=num[i]; // } // console.log(sum) // Constants // const initialRikshawCost = 130000; // const monthlyRevenuePerRikshaw = 6500; // const monthlyMaintenance = 1700; // const monthlyInterest = 1800; // const monthlyProfitPerRikshaw = 3000; // const rikshawLife = 60; // months // const targetProfit = 10000000; // 1 crore // const loanThresholdSaving = 90000; // Amount to save before taking a loan // const newRikshawCost = 150000; // New rikshaw cost // const loanInterestPerMonth = 0.20 / 12; // 20% annual interest divided by 12 months // let totalProfit = 0; // Total accumulated profit // let rikshawCount = 1; // Starting with 1 rikshaw // let rikshawLifetimes = [rikshawLife]; // Remaining life of each rikshaw // let activeLoans = []; // Active loans // let totalMonths = 0; // Time tracker // // Function to process each month // function processMonth() { // let monthlyTotalProfit = 0; // // Calculate monthly profit from all active rikshaws // rikshawLifetimes = rikshawLifetimes.map((life, i) => { // if (life > 0) { // monthlyTotalProfit += monthlyProfitPerRikshaw; // return life - 1; // Reduce life by 1 month // } // return life; // }); // totalProfit += monthlyTotalProfit; // // Process active loans // activeLoans = activeLoans.map((loan) => { // if (loan.remainingMonths > 0) { // totalProfit -= loan.emi; // return { remainingMonths: loan.remainingMonths - 1, emi: loan.emi }; // } // return loan; // }).filter(loan => loan.remainingMonths > 0); // // Buy new rikshaw if enough savings (90k saved) // if (totalProfit >= loanThresholdSaving) { // totalProfit -= loanThresholdSaving; // // New loan for remaining amount (150k - 90k) // let newLoanAmount = newRikshawCost - loanThresholdSaving; // let emi = newLoanAmount * loanInterestPerMonth; // activeLoans.push({ remainingMonths: 12, emi: emi }); // // Add new rikshaw // rikshawCount++; // rikshawLifetimes.push(rikshawLife); // } // totalMonths++; // } // // Run the simulation until profit goal is reached // while (totalProfit < targetProfit) { // processMonth(); // } // console.log(`It will take ${totalMonths} months to reach 1 crore profit.`); // // Constants // const initialRikshawCost = 130000; // const monthlyRevenuePerRikshaw = 6500; // const monthlyMaintenance = 1700; // const monthlyInterest = 1800; // const monthlyProfitPerRikshaw = 3000; // const rikshawLife = 60; // months // const targetProfit = 10000000; // 1 crore // const loanThresholdSaving = 90000; // Amount to save before taking a loan // const newRikshawCost = 150000; // New rikshaw cost // const loanInterestPerMonth = 0.20 / 12; // 20% annual interest divided by 12 months // // Function to start the simulation with dynamic initial rikshaw count // function simulateRikshawBusiness(initialRikshawCount) { // let totalProfit = 0; // Total accumulated profit // let rikshawCount = initialRikshawCount; // Starting with user-defined rikshaw count // let rikshawLifetimes = Array(rikshawCount).fill(rikshawLife); // Remaining life of each rikshaw // let activeLoans = []; // Active loans // let totalMonths = 0; // Time tracker // // Function to process each month // function processMonth() { // let monthlyTotalProfit = 0; // // Calculate monthly profit from all active rikshaws // rikshawLifetimes = rikshawLifetimes.map((life, i) => { // if (life > 0) { // monthlyTotalProfit += monthlyProfitPerRikshaw; // return life - 1; // Reduce life by 1 month // } // return life; // }); // totalProfit += monthlyTotalProfit; // // Process active loans // activeLoans = activeLoans.map((loan) => { // if (loan.remainingMonths > 0) { // totalProfit -= loan.emi; // return { remainingMonths: loan.remainingMonths - 1, emi: loan.emi }; // } // return loan; // }).filter(loan => loan.remainingMonths > 0); // // Buy new rikshaw if enough savings (90k saved) // if (totalProfit >= loanThresholdSaving) { // totalProfit -= loanThresholdSaving; // // New loan for remaining amount (150k - 90k) // let newLoanAmount = newRikshawCost - loanThresholdSaving; // let emi = newLoanAmount * loanInterestPerMonth; // activeLoans.push({ remainingMonths: 12, emi: emi }); // // Add new rikshaw // rikshawCount++; // rikshawLifetimes.push(rikshawLife); // } // totalMonths++; // } // // Run the simulation until profit goal is reached // while (totalProfit < targetProfit) { // processMonth(); // } // console.log(`With ${initialRikshawCount} rikshaws initially, it will take ${totalMonths} months to reach 1 crore profit.`); // } // // Example: Change the number of rikshaws dynamically // simulateRikshawBusiness(10); // Start with 3 rikshaws // // Constants // const initialRikshawCost = 130000; // const monthlyRevenuePerRikshaw = 6500; // const monthlyMaintenance = 1700; // const monthlyInterest = 1800; // const monthlyProfitPerRikshaw = 3000; // const rikshawLife = 60; // months // const targetProfit = 10000000; // 1 crore // const loanThresholdSaving = 90000; // Amount to save before taking a loan // const newRikshawCost = 150000; // New rikshaw cost // const loanInterestPerMonth = 0.20 / 12; // 20% annual interest divided by 12 months // // Function to start the simulation with dynamic initial rikshaw count // function simulateRikshawBusiness(initialRikshawCount) { // let totalProfit = 0; // Total accumulated profit // let rikshawCount = initialRikshawCount; // Starting with user-defined rikshaw count // let rikshawLifetimes = Array(rikshawCount).fill(rikshawLife); // Remaining life of each rikshaw // let activeLoans = []; // Active loans // let totalMonths = 0; // Time tracker // // Function to process each month // function processMonth() { // let monthlyTotalProfit = 0; // // Calculate monthly profit from all active rikshaws // rikshawLifetimes = rikshawLifetimes.map((life, i) => { // if (life > 0) { // monthlyTotalProfit += monthlyProfitPerRikshaw; // return life - 1; // Reduce life by 1 month // } // return life; // }); // totalProfit += monthlyTotalProfit; // // Process active loans // activeLoans = activeLoans.map((loan) => { // if (loan.remainingMonths > 0) { // totalProfit -= loan.emi; // return { remainingMonths: loan.remainingMonths - 1, emi: loan.emi }; // } // return loan; // }).filter(loan => loan.remainingMonths > 0); // // Buy new rikshaw if enough savings (90k saved) // if (totalProfit >= loanThresholdSaving) { // totalProfit -= loanThresholdSaving; // // New loan for remaining amount (150k - 90k) // let newLoanAmount = newRikshawCost - loanThresholdSaving; // let emi = newLoanAmount * loanInterestPerMonth; // activeLoans.push({ remainingMonths: 12, emi: emi }); // // Add new rikshaw // rikshawCount++; // rikshawLifetimes.push(rikshawLife); // } // totalMonths++; // } // // Run the simulation until profit goal is reached // while (totalProfit < targetProfit) { // processMonth(); // } // console.log(`With ${initialRikshawCount} rikshaws initially, it will take ${totalMonths} months to reach 1 crore profit.`); // // Calculate how many rikshaws still have life left after target is reached // let rikshawsWithRemainingLife = rikshawLifetimes.filter(life => life > 0); // console.log(`After reaching 1 crore, there are ${rikshawsWithRemainingLife.length} rikshaws with remaining life.`); // console.log(`Remaining months for these rikshaws:`, rikshawsWithRemainingLife); // } // // Example: Change the number of rikshaws dynamically // simulateRikshawBusiness(3); // Start with 3 rikshaws // Constants // const initialRikshawCost = 130000; // const monthlyRevenuePerRikshaw = 6500; // const monthlyMaintenance = 1700; // const monthlyInterest = 1800; // const monthlyProfitPerRikshaw = 3000; // const rikshawLife = 60; // months // const targetProfit1Cr = 10000000; // 1 crore // const targetProfitBig = 100000// 2 crore // const loanThresholdSaving = 90000; // Amount to save before taking a loan // const newRikshawCost = 150000; // New rikshaw cost // const loanInterestPerMonth = 0.20 / 12; // 20% annual interest divided by 12 months // // Function to start the simulation with dynamic initial rikshaw count // function simulateRikshawBusiness(initialRikshawCount) { // let totalProfit = 0; // Total accumulated profit // let rikshawCount = initialRikshawCount; // Starting with user-defined rikshaw count // let rikshawLifetimes = Array(rikshawCount).fill(rikshawLife); // Remaining life of each rikshaw // let activeLoans = []; // Active loans // let totalMonths = 0; // Time tracker // let monthsTo1Cr = 0; // Months to reach 1 crore // let monthsTo2Cr = 0; // Months to reach 2 crore // let reached1Cr = false; // // Function to process each month // function processMonth() { // let monthlyTotalProfit = 0; // // Calculate monthly profit from all active rikshaws // rikshawLifetimes = rikshawLifetimes.map((life, i) => { // if (life > 0) { // monthlyTotalProfit += monthlyProfitPerRikshaw; // return life - 1; // Reduce life by 1 month // } // return life; // }); // totalProfit += monthlyTotalProfit; // // Process active loans // activeLoans = activeLoans.map((loan) => { // if (loan.remainingMonths > 0) { // totalProfit -= loan.emi; // return { remainingMonths: loan.remainingMonths - 1, emi: loan.emi }; // } // return loan; // }).filter(loan => loan.remainingMonths > 0); // // Buy new rikshaw if enough savings (90k saved) // if (totalProfit >= loanThresholdSaving) { // totalProfit -= loanThresholdSaving; // // New loan for remaining amount (150k - 90k) // let newLoanAmount = newRikshawCost - loanThresholdSaving; // let emi = newLoanAmount * loanInterestPerMonth; // activeLoans.push({ remainingMonths: 12, emi: emi }); // // Add new rikshaw // rikshawCount++; // rikshawLifetimes.push(rikshawLife); // } // totalMonths++; // // Track when we reach 1 crore // if (!reached1Cr && totalProfit >= targetProfit1Cr) { // monthsTo1Cr = totalMonths; // reached1Cr = true; // // Calculate remaining rikshaws with life after 1 crore // let rikshawsWithRemainingLife = rikshawLifetimes.filter(life => life > 0); // console.log(`It took ${monthsTo1Cr} months to reach 1 crore profit.`); // console.log(`After reaching 1 crore, there are ${rikshawsWithRemainingLife.length} rikshaws with remaining life.`); // console.log(`Remaining months for these rikshaws:`, rikshawsWithRemainingLife); // } // } // // Run the simulation until we reach 2 crore // while (totalProfit < targetProfitBig) { // processMonth(); // } // monthsTo2Cr = totalMonths; // console.log(`It took ${monthsTo2Cr} months to reach ${targetProfitBig} your dream profit.`); // } // // Example: Change the number of rikshaws dynamically // simulateRikshawBusiness(1); // Start with 3 rikshaws // Constants // const initialRikshawCost = 130000; // const monthlyRevenuePerRikshaw = 6500; // const monthlyMaintenance = 1700; // const monthlyInterest = 1800; // const monthlyProfitPerRikshaw = 3000; // const rikshawLife = 60; // months // const loanThresholdSaving = 90000; // Amount to save before taking a loan // const newRikshawCost = 150000; // New rikshaw cost // const loanInterestPerMonth = 0.20 / 12; // 20% annual interest divided by 12 months // // Function to start the simulation with dynamic initial rikshaw count and target profit // function simulateRikshawBusiness(initialRikshawCount, targetProfit) { // let totalProfit = 0; // Total accumulated profit // let rikshawCount = initialRikshawCount; // Starting with user-defined rikshaw count // let rikshawLifetimes = Array(rikshawCount).fill(rikshawLife); // Remaining life of each rikshaw // let activeLoans = []; // Active loans // let totalMonths = 0; // Time tracker // let monthsToTarget = 0; // Months to reach target profit // // Function to process each month // function processMonth() { // let monthlyTotalProfit = 0; // // Calculate monthly profit from all active rikshaws // rikshawLifetimes.forEach((life, i) => { // if (life > 0) { // monthlyTotalProfit += monthlyProfitPerRikshaw; // rikshawLifetimes[i] = life - 1; // Reduce life by 1 month // } // }); // totalProfit += monthlyTotalProfit; // // Process active loans // activeLoans = activeLoans.map((loan) => { // if (loan.remainingMonths > 0) { // totalProfit -= loan.emi; // return { remainingMonths: loan.remainingMonths - 1, emi: loan.emi }; // } // return loan; // }).filter(loan => loan.remainingMonths > 0); // // Buy new rikshaw if enough savings (90k saved) // if (totalProfit >= loanThresholdSaving) { // totalProfit -= loanThresholdSaving; // // New loan for remaining amount (150k - 90k) // let newLoanAmount = newRikshawCost - loanThresholdSaving; // let emi = newLoanAmount * loanInterestPerMonth; // activeLoans.push({ remainingMonths: 12, emi: emi }); // // Add new rikshaw // rikshawCount++; // rikshawLifetimes.push(rikshawLife); // } // totalMonths++; // } // // Run the simulation until the target profit is reached // while (totalProfit < targetProfit) { // processMonth(); // } // monthsToTarget = totalMonths; // console.log(`With ${initialRikshawCount} rikshaws initially, it will take ${monthsToTarget} months to reach a profit of ₹${targetProfit}.`); // } // // Example: Change the number of rikshaws and target profit dynamically // simulateRikshawBusiness(3, 1000000); // Start with 3 rikshaws and target profit of 1 crore function shuffleString(indices, s) { let n = s.length; let result = new Array(n); for (let i = 0; i < n; i++) { result[indices[i]] = s[i]; } console.log(result.join("")); } // Sample Input let n = 8; let str = "acciojob"; let arr = [4, 5, 6, 7, 0, 2, 1, 3]; // Call the function with sample input shuffleString(arr, str);
Write, Run & Share Javascript code online using OneCompiler's JS online compiler for free. It's one of the robust, feature-rich online compilers for Javascript language. Getting started with the OneCompiler's Javascript editor is easy and fast. The editor shows sample boilerplate code when you choose language as Javascript and start coding.
Javascript(JS) is a object-oriented programming language which adhere to ECMA Script Standards. Javascript is required to design the behaviour of the web pages.
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
rl.on('line', function(line){
console.log("Hello, " + line);
});
Keyword | Description | Scope |
---|---|---|
var | Var is used to declare variables(old way of declaring variables) | Function or global scope |
let | let is also used to declare variables(new way) | Global or block Scope |
const | const is used to declare const values. Once the value is assigned, it can not be modified | Global or block Scope |
let greetings = `Hello ${name}`
const msg = `
hello
world!
`
An array is a collection of items or values.
let arrayName = [value1, value2,..etc];
// or
let arrayName = new Array("value1","value2",..etc);
let mobiles = ["iPhone", "Samsung", "Pixel"];
// accessing an array
console.log(mobiles[0]);
// changing an array element
mobiles[3] = "Nokia";
Arrow Functions helps developers to write code in concise way, it’s introduced in ES6.
Arrow functions can be written in multiple ways. Below are couple of ways to use arrow function but it can be written in many other ways as well.
() => expression
const numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
const squaresOfEvenNumbers = numbers.filter(ele => ele % 2 == 0)
.map(ele => ele ** 2);
console.log(squaresOfEvenNumbers);
let [firstName, lastName] = ['Foo', 'Bar']
let {firstName, lastName} = {
firstName: 'Foo',
lastName: 'Bar'
}
const {
title,
firstName,
lastName,
...rest
} = record;
//Object spread
const post = {
...options,
type: "new"
}
//array spread
const users = [
...adminUsers,
...normalUsers
]
function greetings({ name = 'Foo' } = {}) { //Defaulting name to Foo
console.log(`Hello ${name}!`);
}
greet() // Hello Foo
greet({ name: 'Bar' }) // Hi Bar
IF is used to execute a block of code based on a condition.
if(condition){
// code
}
Else part is used to execute the block of code when the condition fails.
if(condition){
// code
} else {
// code
}
Switch is used to replace nested If-Else statements.
switch(condition){
case 'value1' :
//code
[break;]
case 'value2' :
//code
[break;]
.......
default :
//code
[break;]
}
For loop is used to iterate a set of statements based on a condition.
for(Initialization; Condition; Increment/decrement){
//code
}
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while (condition) {
// code
}
Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.
do {
// code
} while (condition);
ES6 introduced classes along with OOPS concepts in JS. Class is similar to a function which you can think like kind of template which will get called when ever you initialize class.
class className {
constructor() { ... } //Mandatory Class method
method1() { ... }
method2() { ... }
...
}
class Mobile {
constructor(model) {
this.name = model;
}
}
mbl = new Mobile("iPhone");