Moneybag Posted October 4, 2014 Report Share Posted October 4, 2014 (edited) Boas Pessoal Estou a iniciar me com javascript e estou aqui com um pequeno problema num bloco de codigo: var total; var orangeCost = function(price) { //total price of 5 orange total = price*5; } console.log(orangeCost(0.20).toString()); Erro Retornado: TypeError: orangeCost(...) is undefined Moderadores apaguem-me este tópico sff que vergonha xD Resposta OBVIA: console.log(total); A função não retorna nada 😄 Edited October 4, 2014 by Ascensao Link to comment Share on other sites More sharing options...
alexviseu Posted October 4, 2014 Report Share Posted October 4, 2014 E provavelmente não te fazia mal um ; no final da instrução onde declaras a função. 1 Report Link to comment Share on other sites More sharing options...
KTachyon Posted October 4, 2014 Report Share Posted October 4, 2014 Mas não podes colocar o ;, porque tens que colocar a implementação da função logo de seguida entre chavetas. “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare Link to comment Share on other sites More sharing options...
alexviseu Posted October 4, 2014 Report Share Posted October 4, 2014 As chavetas fazem parte do valor a ser afectado. O ; vem depois 🙂 Link to comment Share on other sites More sharing options...
KTachyon Posted October 5, 2014 Report Share Posted October 5, 2014 Sim, tens razão. Interpretei mal o teu "final da instrução". “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare Link to comment Share on other sites More sharing options...
taviroquai Posted October 5, 2014 Report Share Posted October 5, 2014 O código devia estar no modo strict. Nada de chamar variáveis globais, ou seja fora do escopo do ficheiro, tornando-o inutilizável. Passa sempre o código por um controlo de qualidade como por exemplo JSLint. Link to comment Share on other sites More sharing options...
Moneybag Posted October 6, 2014 Author Report Share Posted October 6, 2014 Obrigado pelas dicas 😉 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now