Skip to main content

Posts

Showing posts with the label JavaScript

PDF Merger Code in JavaScript

Hello, The following code uses the pdf-merger-js node.js library. You can read more about it here . 1. Create a new folder at your desired location (Folder Name - Merge PDF). 2. Inside this folder, create a new JavaScript file (File Name - mergerCode.js). 3. Open a terminal inside the newly created folder and execute the following command     npm init 4. Few questions would be asked related to creation of new package. If you don't want to modify anything, follow the prompts. A new package.json file will be created. 5. Edit this package.json file and add "type":"module" 6. Now execute the following command in the terminal     npm install --save pdf-merger-js 7. Add the code given below in the mergerCode file. 8. Save the file and execute  node <fileName.js> Source Code - You can add as many PDF files as you want.  In the parenthesis mention the path/filename of the PDF. import PDFMerger from "pdf-merger-js" ; var merger = new PDFMerger (); ...

JavaScript - setTimeout and setInterval

Working with Timers Complete the function "logString" in the editor below. 'logString" has the following parameters:      input:stringToLog Write a timer function to log "Logging {stringToLog} every 0.5 seconds" 0.3 seconds after the server is started. Write a timer function to log "{stringToLog}" every 0.5 seconds and the string should log 5 times. Once the code is written, click Run Tests to run the test cases. Solution: function logString ( stringToLog ) {   let counter = 0 ;   function printSetTimeout () {     console . log ( `Logging ${ stringToLog } every 0.5 seconds` );   }   setTimeout ( printSetTimeout , 300 );   let timer = setInterval ( function () {     counter ++;     if ( counter === 5 ) clearInterval ( timer );     console . log ( stringToLog );   }, 500 ); }