Mode entretien. Minuteur de 4 min, sans indices ni autocomplétion
Field from a response
FacileJSON and data4 min
A test got the body of an API response as a JSON string. The product is in the field data.product. Write a function getProduct(body) that returns an object with only the name and price of that product.
Exemples
getProduct('{"status":200,"data":{"product":{"id":7,"name":"Phone","price":300}}}')Renvoie { name: 'Phone', price: 300 }
Chargement de l'éditeur...
- Entrée
getProduct('{"status":200,"data":{"product":{"id":7,"name":"Phone","price":300}}}')Attendu{ name: 'Phone', price: 300 } - Entrée
getProduct('{"status":200,"data":{"product":{"id":12,"name":"Laptop","price":1500,"stock":4}}}')Attendu{ name: 'Laptop', price: 1500 }
Les tests cachés se lancent à la soumission