我正在做一个涉及对象的练习,并使用CodePen上的控制台查看输出。我已经编写了以下代码,但是控制台未提供任何输出,有人可以帮助我指出我的代码有什么问题吗?
我需要打印“在学校,我将学习ExpressJS和ReactJS。”使用模板字符串。
{
let basic = {
language: "JavaScript",
frameworks: [{
end: "back",
list: [{
name: "ExpressJS",
released: 2010
},
{
name: "MeteorJS",
released: 2012
}
]
},
{
end: "front",
list: [{
name: "ReactJS",
released: 2013
},
{
name: "VueJS",
released: 2014
}
]
}
]
};
}
console.log(basic.frameworks[0].list[0].name); // => ExpressJS
console.log(`In school I will learn ${basic.frameworks[0].list[0].name} and ${(basic.frameworks[0].list[0].name}`); // => In school, I'll learn ExpressJS and ReactJS.
答案 0 :(得分:1)
您接近了!您几乎不需要更改
(
移除${(basic.frameworks[0].list[0].name}
{}
下。那应该可以解决您的麻烦!
let basic = {
language: 'JavaScript',
frameworks: [{
end: 'back',
list: [{
name: 'ExpressJS',
released: 2010
}, {
name: 'MeteorJS',
released: 2012
}]
}, {
end: 'front',
list: [{
name: 'ReactJS',
released: 2013
}, {
name: 'VueJS',
released: 2014
}]
}]
};
console.log(basic.frameworks[0].list[0].name); // => ExpressJS
console.log(`In school I will learn ${basic.frameworks[0].list[0].name} and ${basic.frameworks[0].list[0].name}`);
答案 1 :(得分:0)
这是因为未定义<html>
<body>
<div class="wrapper">
<header>
<div class="header-wrap">
<div class="logo">
<img src="https://placekitten.com/200/50" alt="logo" />
</div>
<div class="join-link">
<a href="#">Join us</a>
</div>
</div>
</header>
<div class="join-link">
<a href="#">Join us</a>
</div>
<section>
<h1>Content section</h1>
<p>Recusandae eius et distinctio numquam ut culpa. Facilis eligendi molestiae rerum esse. Dolorem nostrum distinctio voluptas. Rerum iste et tenetur necessitatibus. Quidem voluptas quo omnis recusandae aut eum totam omnis. Repellendus blanditiis corporis ut aliquid sunt aut cupiditate aliquam.</p>
</section>
<div class="push"></div>
</div>
<footer>
This is the footer
</footer>
<script src="src/index.js">
</script>
</body>
</html>
(请查看浏览器控制台)。
在变量定义前后删除括号basic