Posts

Showing posts from February, 2025

PRogram to demonstrate asynch/await, promise call back in javascript

5. b. Simulate a periodic stock price change and display on the console. Hints: (i) Create a method which returns a random number - use Math.random, floor and other methods to return a rounded value. (ii) Invoke the method for every three seconds and stop , use Asynchronous Programming, Callbacks, Promises, Async and Await   without graphics **************** function getRandomStockPrice() {     return (Math.random() * (200 - 100) + 100).toFixed(2); // Generates a price between 100 and 200 } async function simulateStockPriceUpdates(interval, updatesCount) {     console.log("Starting stock price simulation...");          for (let i = 0; i < updatesCount; i++) {         await new Promise(resolve => setTimeout(resolve, interval));         console.log(`Stock Price Update ${i + 1}: $${getRandomStockPrice()}`);     }          console.log("Simulation ended."); } sim...