Knowee
Questions
Features
Study Tools

In the file 0-console.js, create a function named displayMessage that prints in STDOUT the string argument.bob@dylan:~$ cat 0-main.jsconst displayMessage = require('./0-console');displayMessage("Hello NodeJS!");bob@dylan:~$ node 0-main.jsHello NodeJS!bob@dylan:~$

Question

In the file 0-console.js, create a function named displayMessage that prints in STDOUT the string argument.bob@dylan:~cat0main.jsconstdisplayMessage=require(./0console);displayMessage("HelloNodeJS!");bob@dylan:  cat 0-main.jsconst displayMessage = require('./0-console');displayMessage("Hello NodeJS!");bob@dylan:~ node 0-main.jsHello NodeJS!bob@dylan:~$

🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is how you can create a function named displayMessage that prints in STDOUT the string argument in the file 0-console.js.

  1. Open the file 0-console.js in your text editor.

  2. Write the following code in the file:

function displayMessage(message) {
    console.log(message);
}

module.exports = displayMessage;

In this code, we define a function displayMessage that takes one argument message. Inside the function, we use console.log to print the message to STDOUT. Finally, we export the function using module.exports so that it can be imported and used in other files.

  1. Save the file and close it.

  2. Now, you can use the displayMessage function in your 0-main.js file as shown in your question. When you run node 0-main.js, it will print "Hello NodeJS!" to STDOUT.

This problem has been solved

Similar Questions

Which method is commonly used to log messages to the console in JavaScript?a) console.print()console.write()console.log()console.display()

What will be the output of the following code in the console?File: my_module.js  exports.name = 'Zeus';  Code:  var my_module = require('./mymodule');  console.log((function(settings){      return settings.split('').reverse().join('')   })(my_module.name)); (1 Point)ErrorsueZundefinedZeus

create a class Greet that reads in from the console a string, and then outputs a greeting Hi ...!, where the name replaces the elipses. e.g. If the input is Hugh then your output should be Hi Hugh!.

How can you print what is stored in a JavaScript variable?(1 Point)log(variable)console.log(variable)print(variable)extract(variable)

Which function is used to print a message on the console in C++?Select one:cout<<;cin>>;Printf()printf();

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.