You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JavaScript:使用&&与&处理数字时的结果差异

帮你梳理JS代码问题

Hey there! Let's work through this together. First off, I see your code snippet cuts off mid-line at Mark = markHeight + 5 * mark...—that's likely a key piece we need to fix first. Let me start by formatting your existing code clearly:

var johnAge = 25;
var markAge = 30;
var steveAge = 40;
var johnHeight = 170;
var markHeight = 175;
var steveHeight = 150;
var John, Mark, Steve;
John = johnHeight + 5 * johnAge;
Mark = markHeight + 5 * mark... // 这里代码截断了!

From what's here, I can spot a couple of things that might be causing issues, plus some quick improvements:

  • Truncated code: The line for calculating Mark is incomplete. I'm guessing you meant to use markAge here, so it should be Mark = markHeight + 5 * markAge;—and similarly, Steve's calculation would follow the same pattern: Steve = steveHeight + 5 * steveAge;.
  • Inconsistent variable naming: You're using uppercase starting letters for John, Mark, Steve but lowercase for johnAge, markHeight, etc. JavaScript is case-sensitive, so this won't break your code outright, but it's easy to mix up names accidentally. Sticking to a consistent style (like camelCase, where all variables start with lowercase and use caps for subsequent words) makes your code cleaner and easier to debug.
  • Variable declaration grouping: You can group all your var declarations together at the top to keep things organized, instead of spreading them out across multiple lines.

Here's a cleaned-up version of what your code might look like once completed:

// 统一用驼峰式命名,分组声明变量
var johnAge = 25,
    markAge = 30,
    steveAge = 40,
    johnHeight = 170,
    markHeight = 175,
    steveHeight = 150,
    johnScore,
    markScore,
    steveScore;

// 完成计算逻辑
johnScore = johnHeight + 5 * johnAge;
markScore = markHeight + 5 * markAge;
steveScore = steveHeight + 5 * steveAge;

Since you mentioned the problem isn't super complex, could you share a bit more detail? Are you getting a specific error message? Is the output not what you expected? Once you fill in that missing code snippet and tell us what's going wrong, we can nail this down quickly!

内容的提问来源于stack exchange,提问作者Anmar Jihad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 03:36:47