Example 1
Input
{
"precioManzanas": 300,
"precioNaranjas": 250,
"cantidadManzanas": 4,
"cantidadNaranjas": 2
}Expected result
1700
Nexo is preparing the challenges…
Nexo · Connect the ideas
Calculate the total cost of a market purchase by breaking the problem into sequential subtotals for apples and oranges.
algoritmos-secuenciales · aritmetica · entrada-salida
A sequential algorithm solves a problem by breaking it into ordered input, processing, and output steps, where each instruction completes a clear task before moving to the next.
In input, you receive an object with the details of a purchase at a market stall:
precioManzanas: unit price of each apple in whole pesos.cantidadManzanas: number of apples purchased.precioNaranjas: unit price of each orange in whole pesos.cantidadNaranjas: number of oranges purchased.Decompose the calculation into sequential steps:
0 and 1000 (inclusive).input.property), basic arithmetic operations (* and +), and return. Do not use conditionals, loops, arrays, advanced methods, or console.log as output.Complete function solve(input) and return the resulting integer. The input always satisfies the described constraints. Do not use network calls, files, imports, packages, or asynchronous code.
Input
{
"precioManzanas": 300,
"precioNaranjas": 250,
"cantidadManzanas": 4,
"cantidadNaranjas": 2
}Expected result
1700
Input
{
"precioManzanas": 450,
"precioNaranjas": 200,
"cantidadManzanas": 1,
"cantidadNaranjas": 5
}Expected result
1450
Input
{
"precioManzanas": 500,
"precioNaranjas": 350,
"cantidadManzanas": 3,
"cantidadNaranjas": 0
}Expected result
1500
Implement solve(input) and return the result. Synchronous JavaScript, without packages, network or account access.
76/10.000 characters · In the advanced editor, press Escape and then Tab to leave.
Your code is restored in this browser. Saving to your account is optional.
Try solving it first. Viewing the solution records assisted use.