首页 > 解决方案 > 当我添加两件事时,它会显示 [object Object] [object Object]

问题描述

当我运行代码(见要点)时,机会制作了一个 40 字符串长的数字集,然后用于制作另一个数字集。这个数字通常看起来像这样。0.8492767284624279 0.23668391536921263 然后我尝试将两者相加,并在控制台中得到 [object Object][object Object]。

我真的不知道该尝试什么。谷歌没有帮助我

const crypto = require('crypto')
var Chance = require('chance');
var chance = new Chance();
//getting everything I need
var 1 = chance.hash({length: 40})
var 2 = chance.hash({length: 40})
//makes two hashes
console.log(1)
console.log(2)
//logs the two hashes
var out1 = new Chance(1);
var out2 = new Chance(2);
//uses the two hashes above to make new numbers

console.log(out1.random());
console.log(out2.random());
//logs the new numbers
var roundOutcome = out1 + out2; 
// Above is where the issue happenes.
console.log(roundOutcome) 
//this is where it puts the [object Object][object Object] in console

它应该添加两个数字。我真的不知道在这里做什么。无论如何,它总是说[object Object] [object Object]。

标签: javascriptjavascript-objects

解决方案


var roundOutcome = out1.random() + out2.random();

你没有调用方法。

有趣的事实:如果将两个随机数相加,则结果的随机性不如数字本身。


推荐阅读