Remember that the bot will be checking the response, so make sure you use the same emojis, punctuation, wording, and capitalization! Only the messages can be different.
🚧 Test Your Work
To test your work, send your Twilio number a text message. You should still receive a text back that contains a message with the same format and wording as the one below, but now the second secret returned will be random, and no longer the most recent secret stored!
💡 Yay! This means you've successfully queried for and returned a random secret.
1: Modifying the SQL Query
In your createDocument function, you'll first want to modify the original SQL query to now query for all secrets inside your container.
❓ How do I select all secrets?
```js
const querySpec = {
query: "SELECT * from c"
};
```
2: Selecting a Random Item
Next, you'll want to select a random secret by:
Generating a random integer that is strictly less than the length of the array of secrets. (Hint: use Math.floor() and Math.random())
Returning the secret at an index of this random number.
❓ How do I generate a random number for the index?
The `Math.floor()` function returns the [floor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor) of the given number - ie. the largest integer less than or equal to a given number. In the example below, the generated random number will never be greater than `items.length`.
```js
let random_value = Math.floor(items.length * Math.random());
```
💡 Make sure to change your responseMessage to return the correct index of items.
Week 3 Step 8 ⬤⬤⬤⬤⬤⬤⬤⬤◯ | 🕐 Estimated completion: 10-20 minutes
Exposed!!
✅ Task:
Modify the
deepsecrets
Azure Function todeepsecrets/index.js
to thedeepsecrets
branchdeepsecrets
ontomain
, and only merge the pull request when the bot approves your changes!❗ Make sure to return your message in this format:
To test your work, send your Twilio number a text message. You should still receive a text back that contains a message with the same format and wording as the one below, but now the second secret returned will be random, and no longer the most recent secret stored!
1: Modifying the SQL Query
In your
createDocument
function, you'll first want to modify the original SQL query to now query for all secrets inside your container.❓ How do I select all secrets?
```js const querySpec = { query: "SELECT * from c" }; ```2: Selecting a Random Item
Next, you'll want to select a random secret by:
Math.floor()
andMath.random()
)❓ How do I generate a random number for the index?
The `Math.floor()` function returns the [floor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor) of the given number - ie. the largest integer less than or equal to a given number. In the example below, the generated random number will never be greater than `items.length`. ```js let random_value = Math.floor(items.length * Math.random()); ```💡 Make sure to change your responseMessage to return the correct index of
items
.📹 Walkthrough Video