Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.



<div name="myForm" id="myForm">
    <input type="text" id="user" placeholder="type here..." />
  <button type="submit" id="sub">Submit</button>

<div id="out">0</div>


  content:"Score: ";


var neg5 = [
	"son of a bitch",
var neg4 = [
var neg3 = [
	"can't stand",
	"does not work",
	"fed up",
	"green wash",
	"green washing",
	"no fun",
	"not working",
	"screwed up",
var neg2 = [
	"cashing in",
	"dont like",
	"messing up",
	"not good",
var neg1 = [
var pos1 = [
var pos2 = [
var pos3 = [
	"cool stuff",
	"right direction",
var pos4 = [
var pos5 = ["breathtaking", "hurrah", "outstanding", "superb", "thrilled"];

//replaces from each instance of the words in the array
function analyze(txt) {
	var user = txt;
	user = user.toLowerCase();
	var analyze = user;
	var sentPos5 = 0;
	var sentPos4 = 0;
	var sentPos3 = 0;
	var sentPos2 = 0;
	var sentPos1 = 0;
	var sentNeg1 = 0;
	var sentNeg2 = 0;
	var sentNeg3 = 0;
	var sentNeg4 = 0;
	var sentNeg5 = 0;
	var sentiment = 0;
	//this accounts for only matching whole words enclosing the pattern with word boundaries
	//it also adds an random string that should never be seen naturally for counting purposes
	for (var i = 0; i < pos5.length; i++) {
		var pos5Reg = RegExp(
				"\\b" + pos5[i].replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&") + "\\b",
		if (analyze.match(pos5Reg)) {
	for (var i = 0; i < pos4.length; i++) {
		var pos4Reg = RegExp(
				"\\b" + pos4[i].replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&") + "\\b",
		if (analyze.match(pos4Reg)) {
	for (var i = 0; i < pos3.length; i++) {
		var pos3Reg = RegExp(
				"\\b" + pos3[i].replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&") + "\\b",
		if (analyze.match(pos3Reg)) {
	for (var i = 0; i < pos2.length; i++) {
		var pos2Reg = RegExp(
				"\\b" + pos2[i].replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&") + "\\b",
		if (analyze.match(pos2Reg)) {
	for (var i = 0; i < pos1.length; i++) {
		var pos1Reg = RegExp(
				"\\b" + pos1[i].replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&") + "\\b",
		if (analyze.match(pos1Reg)) {
	for (var i = 0; i < neg5.length; i++) {
		var neg5Reg = RegExp(
				"\\b" + neg5[i].replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&") + "\\b",
		if (analyze.match(neg5Reg)) {
	for (var i = 0; i < neg4.length; i++) {
		var neg4Reg = RegExp(
				"\\b" + neg4[i].replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&") + "\\b",
		if (analyze.match(neg4Reg)) {
	for (var i = 0; i < neg3.length; i++) {
		var neg3Reg = RegExp(
				"\\b" + neg3[i].replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&") + "\\b",
		if (analyze.match(neg3Reg)) {
	for (var i = 0; i < neg2.length; i++) {
		var neg2Reg = RegExp(
				"\\b" + neg2[i].replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&") + "\\b",
		if (analyze.match(neg2Reg)) {
	for (var i = 0; i < neg1.length; i++) {
		var neg1Reg = RegExp(
				"\\b" + neg1[i].replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&") + "\\b",
		if (analyze.match(neg1Reg)) {

	//add up all of the number of classes of lexicon words and multiply them by their sentiment score
	sentiment = (sentNeg5 * -5) + (sentNeg4 * -4) + (sentNeg3 * -3) + (sentNeg2 * -2) + (sentNeg1 * -1) + (sentPos1 * 1) + (sentPos2 * 2) + (sentPos3 * 3) + (sentPos4 * 4) + (sentPos5 * 5);

	var totalLex = sentNeg5 + sentNeg4 + sentNeg3 + sentNeg2 + sentNeg1 + sentPos1 + sentPos2 + sentPos3 + sentPos4 + sentPos5;
	//dont let the avg divide by 0
	if (totalLex === 0) {
		totalLex = 1;
	//get the average score to normalize between -5 and 5
	var sentimentAvg = Math.round(sentiment / totalLex * 100) / 100;
	return sentimentAvg;

//page functions (not part of broader library)
function afinn(){
  document.getElementById("out").innerHTML = analyze(document.getElementById("user").value);
document.getElementById("sub").onclick = afinn;

var sub = document.getElementById("user");
sub.addEventListener("keydown", function (e) {
    if (e.keyCode === 13) {  //checks whether the pressed key is "Enter"