【发布时间】:2022-11-19 20:37:44
【问题描述】:
function consoleStyler(color, background, fontSize, txt)
{
var message = "%c" + txt;
var style = `color: ${color}`;
style = `background:${background}`;
style = `fontSize:${fontSize}`;
console.log(style)
}
function celebrateStyler(reason)
{
var fontStyle = "color: tomato; font-size: 50px";
if (reason == "birthday") {
console.log('%cHappy Birthday', fontStyle)
}
else if (reason == 'champions') {
console.log('%cCongrats on the title!', fontstyle)
}
else {
console.log(message, style)
}
}
consoleStyler('#1d5c63', '#ede6db', '40px', 'congrats!');
celebrateStyler('birthday')
function styleAndCelebrate()
{
consoleStyler(color, background, fontSize, txt);
celebrateStyler(reason);
}
styleAndCelebrate('#ef7c8e', '#fae8e0', '30px', 'You made it!', 'champions')
我收到消息未定义的错误。现在我知道 var 是函数作用域的,所以它不能在函数外使用。但 Coursera 上的作业坚持认为
【问题讨论】:
标签: javascript