-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunctions.js
More file actions
148 lines (97 loc) · 4.71 KB
/
functions.js
File metadata and controls
148 lines (97 loc) · 4.71 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// This function returns a random number between (and including both) minimum and maximum
function getRandomInteger (minimum, maximum) {
minimum = Math.ceil(minimum) // minimum is inclusive
maximum = Math.floor(maximum + 1) // maximum is exclusive so we add one
return Math.floor(Math.random() * (maximum - minimum)) + minimum
}
// change
// hello it's me
// June 17
// cool I am also me!
let s = {name: 'Tony', address: 'Sussex Drive'}
// Povided Arrays
const nouns = ['dragons', 'toasters', 'cars']
const verbs = ['walked', 'ran']
const adverbs = ['menacingly', 'intentionally']
const adjectives = ['wild', 'slippery']
const proNouns = ['they', 'we', 'you', 'he', 'she', 'I', 'it']
const openings = ['Once upon a time', 'I watched']
const closings = ['with extra cheese', 'the end']
// Instructions:
// Arrays:
// Each provided array (except for proNouns) must have at least 10 elements (words or phrases)
// Add/replace words to each array based on any theme you like (keep it tasteful!)
// You do not have to use the example words in any of the provided arrays
// Functions:
// First function:
// Create a function that outputs the text/value sent to it using console.log()
// There should be a newline ("\n") both before and after the value is output
// Name this function appropriately
// Note this function does not return any value
// Second function:
// Create a function that builds a sentence using the 7 provided arrays
// Using the provided getRandomInteger function you will randomly use content from each array based on the random number returned by getRandomInt.
// Because you are using an array the minimum value should always be zero
// The maximum value should be the array length - 1
// The sentence created (concatinated) inside this function should be structured like this:
// Get a random element from the openings array and add it to your new sentence
// add a space (and punctuation if you wish)
// next get a random element from the adjectives array and add it to your sentence
// add a space (and punctuation if you wish)
// next get a random element from the nouns array and add it to your sentence
// add a space (and punctuation if you wish)
// next get a random element from the pro_nouns array and add it to your sentence
// add a space (and punctuation if you wish)
// next get a random element from the verbs array and add it to your sentence
// add a space (and punctuation if you wish)
// next get a random element from the adverbs array and add it to your sentence
// add a space (and punctuation if you wish)
// next get a random element from the adjectives array and add it to your sentence
// add closing punctuation.
// Note Feel free to re-arrange your sentence as you wish, just make sure you use the 7 provided arrays
// Note add more arrays if you wish
// Name this function appropriately
// This function should return the completed sentence
// Program Flow:
// inside a loop that repeats 10 times
// Your program will call the "sentence creating" function that you are required to build
// using a new variable you will capture the returned value (the sentence) from this function. Name this variable appropriately
// next you will send this variable to the other function you created used for output
// this will result in your random sentence being output.
// Other considerations:
// Everyones code should be different
// This is a fun exercise so... have fun!
// Submission
// Submit your GitHub repo URL through the LMS.
// Pseudo code:
// add the words to arrays
// Create a function that creates a ranmdom sentence
// Does this function require any parameters: no
// Does this function need to return anything: yes a new random sentence
// how do you create a random sentence?
// Create a function that outputs some text
// Does function require any parameters: yes to text to output
// Does this function need to return anything: no
// execute a loop 10 times
// each cycle of the loop creates a new random sentence and then output it
function createRandomSentence(){
const randomSentence = openings[ getRandomInteger(0, openings.length - 1) ] + ' ' +
// random adjective
adjectives[getRandomInteger(0, adjectives.length - 1)] + ' '
// random noun
// add random pro_noun
// add random verb
// add random adverb // maybe a comma not a space
// add random ending // period at the end
// return this new random sentence
return randomSentence
}
function outputSentence( sentence){
console.log(sentence)
}
const numberOfSentences = 10
for(let i = 0; i < numberOfSentences; i++){
// let randomSentence = createRandomSentence()
// outputSentence(randomSentence)
outputSentence(createRandomSentence())
}