Replace all 0 in an Array with random numbers

Okey, folks so here it is, a solution to replace all the 0os in an array with a number. In the beginning I succeeded replace all 0 with the same number. But then i wanted to replace them with different values, all based on a random number. Here is the solution, written in Javascript:

<html>

<head>
</head>

<body>
<script>

var myData = [];
myData.push(5, 10, 0, 0, 0, 30, 0, 0, 0, 0);

//kanske används vid ett senare tilfälle 
var random = Math.floor((Math.random() * 100) + 1);
var random1 = Math.floor((Math.random() * 100) + 1);
var random2 = Math.floor((Math.random() * 100) + 1);
//

console.log(myData);

for(var i = 0; i < myData.length; i++){
  for(nollor in myData){
    
  if(myData[i] === 0){
    myData[i] = random;  
    random = Math.floor((Math.random() * 100) + 1);   
    myData[i] = random;
    
  }

}

  console.log(myData[i]);
}

</script>
</body>
</html>
Write better jQuery!

Write better jQuery!

jQuery is a great framework that make our life easer when it comes to start writing javascript or manipulate the DOM.

The only problem is that because jQuery make everything easer some developer forget to write good jQuery, that is following almost the same good practices that developers should use when writing JavaScript.

A very simple example of this is the following:

$(“document”).ready(function() {

});

This is the most popular way to start using jQuery. If you don’t care about populating with globals variables or the loading performance is not a worry for you, this kind of code works for you.

But when you are working with bigger applications you don’t want that your variables gets globals and obviously you want the best performance for you app.

The solution is follow the best practices. The example above can be written like this:

(function($, window, document) {

// now $ is locally scoped

$(function() {

// the DOM is ready

});

}(window.jQuery, window, document));

Do you wanna know even more best practices? Take a look to this article, is a must to read:

jQuery BEST PRACTICES

Did you got stuck when styling your fonts?

Did you got stuck when styling your fonts?

As a front-end developer I always have the same problem when I need to define my font-sizes and line-heights in my CSS. Normally I need to take in consideration the base-size of the font to create the sizes of my h-elemnts and add to the equation the line-hight which needs to be proportional. And when all that is in place I go to bed whishing that the customer don’t change the font-type.

Well, to avoid that problem I strongly recommend you type-scale.com.

At type-scale you can choose the font family and base-size and the page will calculate for you the headers and pragraphs sizes and line-heights. You can also choose between different scales i.e. minor third, major third, augmented and a lot more.

Not enough whith that, type-scale generate a CSS-script that can be used in your CSS file with all sizes and line-heights.

Happy coding!!!

First video of our Sass tutorial is online!

First video of our Sass tutorial is online!

 

Hello everybody. I am happy to say that the first video of a serie of videos about Sass is online and you can see it in the Tutorial’s page. I will try to upload new videos in a regular basis, meanwhile send me your feedbacks to have an idea of what I should improve.

This is the first time I create a video serie and I was a little nervous I must to admit. Now I am working in the second one which will be a little longer because we will get our hands dirty creating our workflow with Gulp.

Enjoy this first video and do not miss the next ones!!!

If You Want To Hire A Freelancer Or If You Are One Check This Out

If you are looking for freelancer(s) or if you are one, then check out Upwork.

It’s a site for profesionals looking for a project, or for people looking for a freelancer for their projects. As a freelancer, you decide what price tag to work for for an hour.

With right price and skills you could easily get hired for a project. The rules state that you should apply for a project only if you have the time and the skill to complete it.

I have registered as a freelancer with $50 dollars for an hour of coding. It’s up to you to do what your career, or wallet, requires you to.