From c03b9560899bb5f3c0616ddbfdd55ac0f8cb025e Mon Sep 17 00:00:00 2001 From: nannal Date: Tue, 12 Jan 2021 17:33:52 +0200 Subject: [PATCH] done --- index.js | 126 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 index.js diff --git a/index.js b/index.js new file mode 100644 index 0000000..ae3f48b --- /dev/null +++ b/index.js @@ -0,0 +1,126 @@ + +// dict = {a:1, b:2, c:3} + +// "bum" = ["b","u", "m"] +// sum +// foreach(letter){ +// num =dict(letter) +// sum += num +// } + + + + +function wordscore(word){ + word=word.toLowerCase() + dict={ + a:1,b:2,c:3,d:4,e:5,f:6,g:7,h:8,i:9,j:10,k:11,l:12,m:13,n:14,o:15,p:16,q:17,r:18,s:19,t:20,u:21,v:22,w:23,x:24,y:25,z:26,} + var i = word.length + score=0 + while (i--) { + if (typeof dict[word.charAt(i)] === "number"){ + score=score+dict[word.charAt(i)] + } + } + return score +} + +word="Bumchunder" +console.log(word+" is worth "+wordscore(word)+" points") + +// function wordscore(word){ +// var i = word.length; + +// score=0 +// while (i--) { +// switch (word.charAt(i)) { +// case "a": +// score=score+1 +// break; +// case "b": +// score=score+2 +// break; +// case "c": +// score=score+3 +// break; +// case "d": +// score=score+4 +// break; +// case "e": +// score=score+5 +// break; +// case "f": +// score=score+6 +// break; +// case "g": +// score=score+7 +// break; +// case "h": +// score=score+8 +// break; +// case "i": +// score=score+9 +// break; +// case "j": +// score=score+10 +// break; +// case "k": +// score=score+11 +// break; +// case "l": +// score=score+12 +// break; +// case "m": +// score=score+13 +// break; +// case "n": +// score=score+14 +// break; +// case "o": +// score=score+15 +// break; +// case "p": +// score=score+16 +// break; +// case "q": +// score=score+17 +// break; +// case "r": +// score=score+18 +// break; +// case "s": +// score=score+19 +// break; +// case "t": +// score=score+20 +// break; +// case "u": +// score=score+21 +// break; +// case "v": +// score=score+22 +// break; +// case "w": +// score=score+23 +// break; +// case "x": +// score=score+24 +// break; +// case "y": +// score=score+25 +// break; +// case "z": +// score=score+26 +// break; + +// default: +// break; +// } +// } +// return score +// } + + +// word="Getting hit by a car" +// console.log(word+" is worth "+wordscore(word)+" points") +// console.log(word+" is worth "+wordscore2(word)+" points") \ No newline at end of file