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

huangapple go评论66阅读模式
英文:

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

你尝试过在网上搜索问题的答案或浏览相关的教程文章吗?

以下是一些适用于初学者的资源:

  1. if...else - JavaScript | MDN
  2. w3schools 的 JavaScript 教程

以下是示例代码:

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:

  1. if...else - JavaScript | MDN
  2. JavaScript Tutorial by w3schools.

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.

huangapple
  • 本文由 发表于 2023年8月10日 10:24:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76872275.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定