GoConqr has a new look! Let us know what you think.

Module 2 of 35 · Text

#02

welligton costa

  

/ *

FUNÇÕES DE TUBULAÇÃO

================

1. Escreva 3 funções:

- aquele que adiciona 2 números juntos

- aquele que multiplica 2 números juntos

- um que formata um número para que seja retornado como uma string com um sinal £ antes dele (por exemplo, 20 -> £ 20)

2. Usando a variável StartingValue como entrada, execute as seguintes operações usando todas as suas funções

em uma linha (atribua o resultado à variável badCode):

- adicione 10 ao valor inicial

- multiplique o resultado por 2

- formate-o

3. Escreva uma versão mais legível do que você escreveu na etapa 2 no comentário MELHORES PRÁTICAS. Atribuir

o resultado final para a variável goodCode

* /

 

 

cole e copie --------------------------------------------------->

function add() {

}

function multiply() {

}

function format() {

}

const startingValue = 2

// Why can this code be seen as bad practice? Comment your answer.

let badCode =

/* BETTER PRACTICE */

let goodCode =

/* ======= TESTS - DO NOT MODIFY ===== */

function test(test_name, expr) {

let status;

if (expr) {

status = "PASSED"

} else {

status = "FAILED"

}

console.log(`${test_name}: ${status}`)

}

test('add function - case 1 works', add(1,3) === 4)

test('add function - case 2 works', add(2.4,5.3) === 7.7)

test('multiply function works', multiply(2,3) === 6)

test('format function works', format(16) === "£16")

test('badCode variable correctly assigned', badCode === "£24")

test('goodCode variable correctly assigned', goodCode === "£24")

Instructions

You must submit an attempt for this quiz to progress. You can submit it after the last question.

Go to the chosen module

Feedback

What is it about?

What do you think of the new look?

How do you like it?