Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Decomposition | Functions
JavaScript Ninja
course content

Contenido del Curso

JavaScript Ninja

JavaScript Ninja

1. Basic Controls
2. Advanced Controls
3. Functions
4. Loops
5. If-Else Statements
6. Challenges

book
Decomposition

In this chapter, we will explore the concept of decomposition in programming. Decomposition is the process of breaking down a complex problem into smaller, more manageable parts. This approach not only makes it easier to solve problems but also helps in organizing code in a more readable and maintainable way.

In the context of our Ninja Game, decomposition allows us to create functions that can be reused and combined to perform more complex tasks. By calling functions within other functions, we can build a hierarchy of operations that simplifies the overall task.

Let's look at an example to understand how decomposition works:

js

ninja.js

copy

In the example above, we have a function ninjaController that calls another function lootTunnel three times. The lootTunnel function itself performs a series of actions to collect sushi from a tunnel and then calls moveToNextTunnel to position the ninja for the next tunnel. This layered approach makes the code easier to understand and modify.

Now, it's your turn to practice decomposition by completing the following task.

Tarea

Swipe to start coding

Solución

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 5
js

ninja.js

toggle bottom row

book
Decomposition

In this chapter, we will explore the concept of decomposition in programming. Decomposition is the process of breaking down a complex problem into smaller, more manageable parts. This approach not only makes it easier to solve problems but also helps in organizing code in a more readable and maintainable way.

In the context of our Ninja Game, decomposition allows us to create functions that can be reused and combined to perform more complex tasks. By calling functions within other functions, we can build a hierarchy of operations that simplifies the overall task.

Let's look at an example to understand how decomposition works:

js

ninja.js

copy

In the example above, we have a function ninjaController that calls another function lootTunnel three times. The lootTunnel function itself performs a series of actions to collect sushi from a tunnel and then calls moveToNextTunnel to position the ninja for the next tunnel. This layered approach makes the code easier to understand and modify.

Now, it's your turn to practice decomposition by completing the following task.

Tarea

Swipe to start coding

Solución

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 5
Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
We're sorry to hear that something went wrong. What happened?
some-alt