repl.it
@mcuringa/

Sentiment

ES6

Write a sentiment analysis function with single string parameter. Return 1 for positive, -1 for negative, or 0 for neutral.

fork
loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function sentiment (text) {
  if (text.includes("love")) {
    return 1;
  }

  if (text.includes("hate")) {
    return -1;
  }

  return 0;
}

console.log(sentiment("I love pizza."));

console.log(sentiment("I hate bugs in my code."));

console.log(sentiment("I write Javascript code."));
Babel Compiler v6.4.4 Copyright (c) 2014-2015 Sebastian McKenzie
?