英文:
Given a string variable activity, set the myMood variable to: ’happy’ if the activity is equal to ’coding’ ’bored’ if the activity is anything else
问题
将字符串变量activity的值设定给myMood
变量:
如果activity等于'coding',则将myMood
设为'happy'。
如果activity不等于'coding',则将myMood
设为'bored'。
我真的被困在尝试弄清楚这个语法上,我试了大约18次。
我尝试写了一些条件语句,但没有一个能正常工作。
英文:
Given a string variable activity, set the myMood
variable to:
’happy’ if the activity is equal to ’coding’
’bored’ if the activity is anything else
I'm really stuck trying to figure out the syntax for this, I tried like 18 times
I tried writing a few conditional statements but non of them were working
答案1
得分: 2
你尝试过在网上搜索问题的答案或浏览相关的教程文章吗?
以下是一些适用于初学者的资源:
以下是示例代码:
let activity = 'coding'; // 示例活动
let myMood;
if (activity === 'coding') {
myMood = 'happy';
} else {
myMood = 'bored';
}
console.log(myMood); // 输出:happy
这是如何在 JavaScript 中使用 if...else 语句的基本示例。查看上述教程以获取更全面的指南。
英文:
Have you tried searching for answers to your question online, or browsing through relevant tutorial articles?
Here are some resources for beginners:
and here is example code:
let activity = 'coding'; // Example activity
let myMood;
if (activity === 'coding') {
myMood = 'happy';
} else {
myMood = 'bored';
}
console.log(myMood); // Outputs: happy
This is a basic example of how you can use if...else statements in JavaScript. Check out the aforementioned tutorials for more comprehensive guides.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论