Question: this is my first post so please take it easy on me :)

I am trying to create a reusable function called alertControls(). I am trying to make the arguments bits that I can replace in the html strings called in the function but get an error when I try to do it like this. I have tried a few different ways but am puzzled why this wouldn't work in JS:

```
function alertControls(parent, icon, alert, message) {
  parent = "form-group has-warning has-feedback";
  icon = "warning-sign";
  alert = "warning";
  message = "Password too short";

  $(this).closest("div").removeClass();
  $('.alert').remove();
  $('span').not('.input-group-addon,.hidden-xs,.caret').remove();
  $(this).closest("div").addClass(parent);
  $(this).before('<span class="glyphicon glyphicon-' + icon + 'form-control-feedback" aria-hidden="true"></span>');
  $(this).closest("div").append('<div class="alert alert-' + alert + ' alert-strong is-attached"><em class="glyphicon glyphicon-remove-sign"></em> <strong>' + message + '</strong></div>');
}

```

Then I want to be able to reuse with different values in the function html:

```
alertControls("form-group has-error has-feedback", "error-sign", "error", "Not valid");

```

Many thanks for any help

Answer: 
1. You are assigning new values to parameters. If I've understood a problem, you should change it to:

`message = message || "Password too short";` and so on.

2. Your usage of `this` is incorrect. Maybe you have to pass another one attribute, say `element` and use it instead of `$(this)` so it would be:

`if ($('input#test').val() === "" ) {
 alertControls($('input#test'), "form-group has-error has-feedback", "error-sign", "error", "Not valid");
}`
What you do:

```
function a(b){
 b=1;//overides b
 return b;
 }
 a(5);//returns also 1

```

You override the value of a.
Simply dont do this. If you want to have a standard value, that is used when no value is passed, you can use new ECMA6 syntax:

```
function a(b=1){
return b;
}
a();//returns 1
a(5); //returns 5

```

---

Problem 2:
"this" returns the parent object of a function. if you call your function inside js this will be the window object.

```
function a(){
 return this;
}
a(); //will return window

```

So you need to get the element another way, maybe passing it to the function or using:

```
$("#uniqueselector")

```