5. debugging!?


#1

Im trying to debug it but i cant see whats wrong please help.
The code im trying to debug:
greeting var func{name}(console.log(name)))}
me trying to debug:
var greeting = function (name) {
var func(name);
console.log(name)))};
};
greeting("James");

Please help


#2

Its fine now i posted this and i straight away found the problem


#3

If so please either delete it or tell people looking for an answer what your problem was :smile:


#4

if people want to know how to solve it,

// Nicely written function:
var calculate = function (number) {
var val = number * 10;
console.log(val);
};

// Badly written function with syntax errors!

var greeting = function(name)
{
console.log("hello there" +" "+ name);
};
greeting("Abid");


#5

No, I meant the bugs in @kieron_bro's code that he has found by himself:

var func(name);
console.log(name)))};

I don't like posting "solutions" without explanation and escpacially here I do not consider it helpful as the whole task of the exercise is to spot bugs. A "solution should already be given by showing a working function above the messed up one.


#6

try this:
var greeting=function(name){
var val=name;
console.log(val);
} ;

greeting("zz");
fix this piece of code:
var func(name); to var func=name;


#7

try this :smile:

var greeting = function (name) {
var va1 = name + " " + " Hammad" ;
console.log(va1);
greeting ("hammad")
};


#8

Not really a good idea, here you have the function call inside of the function meaning this code is not run an if it is you trapped in a loop

greeting ("hammad")
    var va1 = name + " " + " Hammad" ;
    console.log(va1);
    greeting ("hammad")
        var va1 = name + " " + " Hammad" ;
        console.log(va1);
        greeting ("hammad")
...

#9

I'm a little bit lost here.

Can you help with the codes to debug them

// Nicely written function:
var calculate = function (number) {
var val = number * 10;
console.log(val);
};

// Badly written function with syntax errors!

greeting var func{name}(console.log(name)))}


#10

@manniebeenie I hope this helps.

var greeting = function (name) {
var name = ("Jamon");
console.log(name)
};
greeting("Jamon");


#11
var name = ("Jamon");

that line is not necessary. That is actually the point of using a parameter name and an argument "Jamon". Together they do exactly this and are even better, becauce the same function would work as well with greeting("digitalmaster77559") whereas using a hard coded value would fail try it.


#12

Thank you for the clarification :smile:


#13

Here's what I have:

// Nicely written function:
var calculate = function(number) {
var val = number * 10;
console.log(val);
};
// Badly written function with syntax errors!
var greeting = function{name) {
console.log(name);
};
greeting("Hercules")

I think I'm close but am still getting rejected. Suggestions appreciated. Thanks.


#14

// Badly written function with syntax errors!
var greeting = function

{name) {
-------- should be (name)

console.log(name);
};


#15

can you help me with this syntax? i'm having trouble with it


#16

this worked thanks haxor


#17

// Nicely written function:
var calculate = function (number) {
var val = number * 10;
console.log(val);
};

// Badly written function with syntax errors!

var greeting = function (name){
console.log("hello"+" "+"james"+" "+"its been a long time");
}
greeting("james");
[this has been solved}


#18

Thank you, that worked


#19

does this seem right guys? When I submitted the code, it said it was right, but I'm thinking it isn't? Because it shows the script on the right side as if it's wrong. Codeacademy seems buggy?

var greeting = function (name) {
var val = greeting
console.log(val + "name");
}
greeting("Abed")


#20

I have my code, but it keeps on saying unexpected token var.

   // Nicely written function:

var calculate = function (number) {
var val = number * 10;
console.log(val);
};

// Badly written function with syntax errors!
var greeting = function(name)
{
console.log("Hi" +" "+ name);
};
greeting("qwertyuiopasdfghjkllzxcvbnm");

suggestions appreciated