exam questions

Exam AZ-204 All Questions

View all questions & answers for the AZ-204 exam

Exam AZ-204 topic 2 question 15 discussion

Actual exam question from Microsoft's AZ-204
Question #: 15
Topic #: 2
[All AZ-204 Questions]

HOTSPOT -
You have a web service that is used to pay for food deliveries. The web service uses Azure Cosmos DB as the data store.
You plan to add a new feature that allows users to set a tip amount. The new feature requires that a property named tip on the document in Cosmos DB must be present and contain a numeric value.
There are many existing websites and mobile apps that use the web service that will not be updated to set the tip property for some time.
How should you complete the trigger?
NOTE: Each correct selection is worth one point.
Hot Area:

Show Suggested Answer Hide Answer
Suggested Answer:

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
dol
Highly Voted 3 years, 11 months ago
Right answer in second drop down is the first one (..."tip" in i...) Similiar example can be found on https://docs.microsoft.com/en-us/azure/cosmos-db/how-to-write-stored-procedures-triggers-udfs
upvoted 173 times
Juanlu
3 years, 11 months ago
After develop a simple Javascript test, de correct option is (..."tip" in i). In cases where "tip" is no defined, sentence "if(isNaN(i)["tip"] || i["tip"] === null)", return "undefined", so it doesn't work properly ! Here this simple test: ---------------- var i = { tip: 5, name: "just a test"} if ('tip' in i){ console.log("YES"); } else { console.log("NO"); } console.log("Option 2"); if(isNaN(i)["tip"] || i["tip"] === null){ // Undefined when "tip: N" not in array ! console.log("NO"); }else { console.log("YES"); }
upvoted 11 times
nychollas
3 years, 4 months ago
because the sintax in the proposed option is NaN(i)["tip"]... it should have been Nan(i["tip"]). In this case, this option might be taken into account as a possible correct answer. This is my opinion.
upvoted 3 times
...
Satheesh88
3 years, 10 months ago
question says tip value should be numeric. What if is gave var i = { tip: 'junk', name: "just a test"} Result: "YES" "Option 2" "NO"
upvoted 6 times
thomastrain
3 years, 10 months ago
Sadheesh88 has a valid point. Although the question states "there will be many apps not updating their value for some time", a good solution should always validate user input. If the value of "tip" is null or "junk", the first option will fail. Option 3 has a typo and is missing a closing parenthesis. If we make a small change to option 3, so it reads: if(isNaN(i["tip"]) || i["tip"] === null){ then this becomes the best answer. Check for yourself with this fiddle: https://jsfiddle.net/d4x3fota/2/ So I think it comes down to if the answers were copied correctly.
upvoted 22 times
DonH
1 year, 4 months ago
thanks for the Fiddle.
upvoted 2 times
...
...
...
zoan
3 years, 10 months ago
I tested the isNaN in and I get 'true' when 'tip' is undefined, null or "a" . But I use isNaN(i['tip']) and not isNaN(i)['tip']. For 'tip' in i I get only if tip is defined the i object regardless of the type of the value.
upvoted 1 times
Tom87
3 years, 8 months ago
isNaN(null) is false. That's why i["tip"] === null is needed too.
upvoted 1 times
...
...
...
MikeAWS
12 months ago
Correct! Second dropdown is: if(!("tip" in i)) { answer can also be found here: https://www.whizlabs.com/blog/microsoft-azure-az-204-exam-questions//
upvoted 2 times
...
jakobste
1 year, 2 months ago
Yes. This question is on Wizlabs also with a variation, and the code there is (..."tip" in i...).
upvoted 1 times
...
sujitwarrier11
3 years, 4 months ago
where is the validation that the tip value is a number? so the current answer is right. isNan checks if the value is not a number. if true it sets value to 0.
upvoted 8 times
altafpatel1984
2 years, 11 months ago
But they suggest IsNaN(i), not isNaN(i["tip"]) which makes no sense as syntax is incorrect.
upvoted 6 times
...
MiraA
3 years ago
My opinion to NaN()... The "old" clients will send no "tip" value at all => set "tip" to 0 to match the new expectations. The "new" clients will send some "tip" value => pass "tip" value to a web service as it is; the web service has possibility to detect NaN() itself and to reject the request as invalid with proper HTTP status code (and log such invalid request to detect malformed clients). The client knows something went wrong and that his request wasn't processed. I consider 0 to be a default value of "tip" which will be used for "old" clients only. Correcting wrong (NaN) values in "tip" to 0 at this moment is bad idea as it hides a problem with the client's communication. A reference to "a numeric value" requirement in the assignment is related to CosmosDB primarily I think.
upvoted 1 times
...
...
...
Skyrocket
Highly Voted 3 years, 9 months ago
Admin, requst you to update answers to avoid any further confusion. 1. getRequest 2. (!"tip" in i) 3. setBody
upvoted 101 times
Forhallf
3 years, 8 months ago
Skyrocket is correct. function validateToDoItemTimestamp() { var context = getContext(); var request = context.getRequest(); // item to be created in the current operation var itemToCreate = request.getBody(); // validate properties if (!("timestamp" in itemToCreate)) { var ts = new Date(); itemToCreate["timestamp"] = ts.getTime(); } // update the item that will be created request.setBody(itemToCreate); } https://docs.microsoft.com/en-us/azure/cosmos-db/how-to-write-stored-procedures-triggers-udfs
upvoted 9 times
...
btrump
3 years, 8 months ago
This is not correct. The prompt states, "must be present and contain a numeric value." if i["tip"] == "foo" your passes but fails to meet the requirement.
upvoted 12 times
jasifu3
2 years, 8 months ago
your argument is valid, but there is no better alternative. isNaN(i)["tip"] is evaluated as false["tip"] -> undefined every time.
upvoted 2 times
...
...
Basu525
3 years, 8 months ago
this is the correct answer. admins please rectify it.
upvoted 4 times
sujitwarrier11
3 years, 4 months ago
where is the validation that the tip value is a number? so the current answer is right. isNan checks if the value is not a number. if true it sets value to 0.
upvoted 4 times
Poops
1 year, 10 months ago
isNaN(i) checks that i is NaN, it will always evaluate to false. That whole snippet is bad, it only compiles because JavaScript has a very forgiving syntax
upvoted 1 times
...
...
...
sujitwarrier11
3 years, 4 months ago
where is the validation that the tip value is a number? so the current answer is right. isNan checks if the value is not a number. if true it sets value to 0.
upvoted 8 times
...
...
HernanP
Most Recent 2 months ago
I'll go for the following: function ensureTip() { var r = getContext().getResponse(); // ✅ Correct selection var i = r.getBody(); if (!("tip" in i)) { // ✅ Correct selection i["tip"] = 0; } r.setBody(i); // ✅ Correct selection }
upvoted 1 times
...
Jak007
9 months ago
Seems like the right answer for the second drop down should be the first alternative (..."tip" in i...)! First and second are correct. Thanks to dol for giving good link and direction. Similiar example can be found on https://docs.microsoft.com/en-us/azure/cosmos-db/how-to-write-stored-procedures-triggers-udfs#pre-triggers
upvoted 2 times
...
dddddd111
11 months, 2 weeks ago
Check out this link with almost same sample code. https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/how-to-write-stored-procedures-triggers-udfs?tabs=javascript function validateToDoItemTimestamp() { var context = getContext(); var request = context.getRequest(); // item to be created in the current operation var itemToCreate = request.getBody(); // validate properties if (!("timestamp" in itemToCreate)) { var ts = new Date(); itemToCreate["timestamp"] = ts.getTime(); } // update the item that will be created request.setBody(itemToCreate); }
upvoted 3 times
...
ENGs
1 year ago
On my exam 2023-10 before the Update of the Exam
upvoted 2 times
...
jakobste
1 year, 2 months ago
This was on the exam in August 2023
upvoted 4 times
...
Sleepers
1 year, 3 months ago
Got this on 06/27/2023 exam
upvoted 4 times
Devendra_Shukla
1 year, 3 months ago
which option you select for second dropdown?
upvoted 1 times
...
...
DonH
1 year, 4 months ago
Just for information: I just had this question on my AZ204 exam - 16-jun-2023. I barely made it (with only 767 points) so I can't inform anyony if this answer is correct or not, just stating that this is an actual exam question.
upvoted 7 times
...
dirtuebus
1 year, 5 months ago
The right answer in the second dropdown, even though it has a little syntax error, has to be by exclusion: if(isNaN(i)["tip"] || i["tip"] === null) { The other options don't check if "tip" is a number, at all. Anyway, even if there is a syntax error, I don't believe the exam is supposed to be a test of our ability to compile the code in our minds :)
upvoted 5 times
...
D58
1 year, 5 months ago
The goal is to set the tip property on the document in Cosmos DB. 3. question's answer should be __.replaceDocument(i) and not r.Body(i) since the document should be replaced (updated) and not only returned to the user (r.Body(i)). See link with examples here: https://learn.microsoft.com/en-us/training/modules/work-with-cosmos-db/4-cosmos-db-stored-procedures
upvoted 1 times
D58
1 year, 5 months ago
Oh never mind: Pretrigger can be used: https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/how-to-write-stored-procedures-triggers-udfs?tabs=javascript#pre-triggers
upvoted 2 times
...
...
fkaracan
1 year, 8 months ago
Question says "tip" should be numeric. Thus isNaN(tip) is correct
upvoted 2 times
...
dimsok
1 year, 8 months ago
The isNaN(i)["tip"] makes no sense as a syntax, isNaN returns true or false. From the line i["tip"] = 0; we can assume i is an array and thus ("tip" in i) is correct
upvoted 2 times
...
saravanasanthosh
1 year, 9 months ago
Got this on 12/30/2022 exam
upvoted 2 times
...
carlosghosn
1 year, 11 months ago
Got this in the exam today ! Nov 25, 2022
upvoted 2 times
...
[Removed]
2 years ago
Microsoft expect us to be polygots knowing Javascript, .Net, Powershell and Bash. Or maybe this exam is to prove that the person is full time busy doing hello-world deployments using different options in Azure. A decent developer uses Azure not try to remember only Azure. This is pointless. The only thing to know is that if other webapps are not yet ready to use that new variable (tip) then it should be set in the trigger to be 0 if not provided (validations are not strictly required because it will fail if the tip is given wrongly as a string and assuming there are no business requirement to set boundaries) The code is not required to check this knowledge. A decent developer knows the art of googling-copy-and-paste.
upvoted 5 times
macobuzi
1 year, 2 months ago
I understand your struggle, but Microsoft also doesn't expect us to study their questions bank to pass their exam. Just like a job interview, many interview questions might not relate to your actual work at all. Still, you need to pass it.
upvoted 1 times
...
r3verse
1 year, 11 months ago
Hey man i keep seeing you post negative about every question in this exam. I do understand your points, but it doesn't add any value to the people trying to learn the questions. It actually decreseas the value to add to it. Your feedback about Microsoft in general can be posted at lots of places, but i don't think this is the best place. Please try to contribute in a way that helps people get the exam!
upvoted 11 times
NombreFalso
1 year, 8 months ago
I think he's pretty fun for comedic relief
upvoted 5 times
...
...
...
[Removed]
2 years ago
I'm a developer and I get a headache looking at that "code". Microsoft should stop thinking these kind of code is the only way to test a "developer". Just look at all these discussions about this answer and what knowledge is it checking? (Memorize what the Microsoft guy wrote in some document as example?)
upvoted 6 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago