我試圖得到一個像這樣的結果
"圓錐體的體積261.66大于圓柱體的體積785:假的。
"圓錐體的體積261.66大于圓柱體的體積785:假。"
。console. log("圓錐體的體積" (10 / 3 * (3。 14 * (5 **2)) "大于圓柱體的體積" (10 * (3.14 * (5 **2)))): 261 > 785);
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
編輯:感謝大家的幫助。我相信我沒有看到我沒有放 " ",并感謝你指出":",我太累了,我只想完成我不相信我浪費了那么多時間讓數學作業,卻錯過了一個 " ",并忘記了:
。你錯過了一個 和":"
使用模板字元
console。 log(`圓錐體的體積${(10 / 3 * (3. 14 * (5 **2))}大于圓柱體的體積 ${(10 * (3。 14 * (5 **2) )} : ${261 > 785}`)。)
uj5u.com熱心網友回復:
String Concatenation
。console. log("圓錐體的體積" (10 / 3 * (3。 14 * (5 **2) ) ) "大于圓柱體的體積" (10 * (3.14 * (5 **2) )) ":" (261 > 785) );
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
請注意(261 > 785)中的括號的重要性。去掉括號將拋出一個false作為輸出。因為控制臺中的字串運算式將與> 785進行檢查,如果括號被洗掉,這將導致false作為結果
OR
模板字數
。console. log(`圓錐體的體積${(10 / 3 * (3. 14 * (5 **2))}大于圓柱體的體積 ${(10 * (3。 14 * (5 **2) )} : ${261 > 785}`);
<iframe name="sif3" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
uj5u.com熱心網友回復:
你錯過了在數字運算式后面添加 或連接,:也應該用引號,因為它是一個字串。最好使用模板,下面的兩個例子:
// With concatination。
console。 log("圓錐體的體積" (10 / 3 * (3。 14 * (5 ** 2) ) ) " 大于圓柱體的體積" (10 * (3.14 * (5 ** 2) ) ) ": " (261 > 785) )。
//With templating
console. log(`圓錐體的體積${(10 / 3 * (3. 14 * (5 ** 2))}大于圓柱體的體積 ${(10 * (3。 14 * (5 ** 2) )}: ${(261 > 785)}`);
<iframe name="sif4" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/306596.html
標籤:
上一篇:蘋果為小學生推出編程指南
下一篇:在d3.js中,是否可以將類的變化應用于selection.classed()的元素,或相對于其currentValue設定一個CSS屬性值?
