我应该添加什么代码以使用 JavaScript 显示以下输出?
What code should i add to display the following output using JavaScript?
期望的输出:-
error : You have been disconnected!
warning : You have been idle for 15 minutes
// Code starts here
// Do not edit this function
function output(msg) {
console.log(this.type, ":", msg)
}
// You may edit below this line not including the .output functions.
var errorMsg = ;
var warningMsg = ;
// Do not edit below this line.
errorMsg.output('You have been disconnected!');
warningMsg.output('You have been idle for 15 minutes');
我不确定你在找这个:
//Desired Output:-
console.error("You have been disconnected!")
console.warn("You have been idle for 15 minutes");
console.log("Code starts here")
// Do not edit this function
function output(msg) {
console.log(this.type, ":", msg)
}
您可以使用函数作为 errorMsg
和 warningMsg
的构造函数,如下所示:
var Logger = function(type) {
this.type = type
this.output = output
}
var errorMsg = new Logger('warning');
var warningMsg = new Logger('error');
这是一个working plunker
如果您还有其他问题,请随时提问。
期望的输出:-
error : You have been disconnected!
warning : You have been idle for 15 minutes
// Code starts here
// Do not edit this function
function output(msg) {
console.log(this.type, ":", msg)
}
// You may edit below this line not including the .output functions.
var errorMsg = ;
var warningMsg = ;
// Do not edit below this line.
errorMsg.output('You have been disconnected!');
warningMsg.output('You have been idle for 15 minutes');
我不确定你在找这个:
//Desired Output:-
console.error("You have been disconnected!")
console.warn("You have been idle for 15 minutes");
console.log("Code starts here")
// Do not edit this function
function output(msg) {
console.log(this.type, ":", msg)
}
您可以使用函数作为 errorMsg
和 warningMsg
的构造函数,如下所示:
var Logger = function(type) {
this.type = type
this.output = output
}
var errorMsg = new Logger('warning');
var warningMsg = new Logger('error');
这是一个working plunker 如果您还有其他问题,请随时提问。