简体   繁体   中英

JavaScript Math Function

Given an object containing the number of positive and negative reviews, for example { positive: 24, negative: 8 }, return the review positivity score.

function getReviewPositivityScore (positive, negative) {
  let a = positive;
  let b = negative;
  let result = a - b  ;
  return  result;
}

module.exports = getReviewPositivityScore;

Error message I get: getReviewPositivityScore 1) should return the number of positive reviews minus the number of negative reviews

0 passing (6ms) 1 failing

  1. getReviewPositivityScore should return the number of positive reviews minus the number of negative reviews:

    AssertionError: expected NaN to deeply equal 16

    • expected - actual

    -NaN +16

    at Context. (.guides/secure/test3.5.1.js:8:17) at processImmediate (internal/timers.js:439:21)

Since you are passing an object you only need one parameter as function input, and then access the values from it:

function getReviewPositivityScore (object) {
   return object.positive - object.negative;
}

Thanks for the quick help. I was able to solve it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM