-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
69 lines (44 loc) · 1.83 KB
/
index.js
File metadata and controls
69 lines (44 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const prompt = require('prompt-sync')();
const axios = require('axios');
// Word variables
let firstWord = "";
let secondWord = "";
let thirdWord = "";
let fourthWord = "";
// Letter variables
let firstLetter = "";
let secondLetter = "";
let thirdLetter = "";
let fourthLetter = "";
console.log("Application will start");
console.log ("Getting words");
async function getRandomWord(character) {
const result = await axios.get("https://api.datamuse.com/words?sp="+character+"*&max=70");
const words = result.data;
var word = words[Math.floor(Math.random()*words.length)];
console.log(`Got word starting with ${character}: ${word.word}`)
return word.word;
}
async function getRelatedWord(relatedWord, character) {
//words related to duck that start with the letter b
// /words?ml=duck&sp=b*
// words that often follow "drink" in a sentence, that start with the letter w
// /words?lc=drink&sp=w*
const result = await axios.get("https://api.datamuse.com/words?lc="+relatedWord+"&sp="+character+"*&max=70");
const words = result.data;
var word = words[Math.floor(Math.random()*words.length)];
console.log(`Got word related to with ${relatedWord}: ${word.word}`)
return word.word;
}
(async () => {
// console.log(await getRandomWord(`o`));
firstLetter = prompt('What is the first letter? ');
secondLetter = prompt('What is the second letter? ');
thirdLetter = prompt('What is the third letter? ');
fourthLetter = prompt('What is the fourth letter? ');
firstWord = await getRandomWord(firstLetter);
secondWord = await getRelatedWord(firstWord, secondLetter);
thirdWord = await getRelatedWord(secondWord , thirdLetter);
fourthWord = await getRelatedWord(thirdWord, fourthLetter);
console.log(`Your random acronym is : ${firstWord} ${secondWord} ${thirdWord} ${fourthWord}`);
})()