Functions

It is simply a collection of codes that can be used again and again rather than writing it multiple times.

You can call it whenever needed.

Example:

Suppose, in your fridge, there are some fruits like apples, kiwis and mangoes and you want to eat but only 1 at a time.

So, to eat any fruit, there are 3 steps –
1.) Open the door of the fridge

2.) Take that fruit out

3.) Close the door.

So, if we are performing these 3 things again and again, and we are performing it for apple, kiwi and mango. So, what we can do, we can create a common function for it, as there are some common actions (like open and close the door) that needs to be formed for all.
function getFruit(foodType){

var type = “”;

“open the door”;

type = foodType;

“close the door”;

return type;

}

getFruit(“apple”);

getFruit(“kiwi”);

getFruit(“mango”);

Looping or Iteration

It is set of instructions that are executed repeatedly.

Example:

Suppose, if a person can eat 4 pizzas. First, he will eat 1st, then, second, then third and fourth.

If we think, there are 3 conditions initial value(pizza= 1), operator (After he eat 1 pizza, now he is going to eat second one, so, now, it will become pizza= previous pizza+1= 2), end-condition (he can eat pizzas until its 4).

Let’s implement it through programmatically.
For Loop:

Syntax: for(initial value, end-condition, operator){ statements = “eat” }

for(var pizza=1; pizza <=4; pizza = pizza +1){

“eat pizza”;

}

While Loop:

Syntax: initial value; while(end-condition) {statements; operator}

var pizza = 1;

While(pizza <=4){

“eat pizza”;

pizza = pizza +1;

}

Conditional Statements

Expression used to check if condition is true or not.

So, definitely, there can be 2 output and based on the output we can perform the required action.

True = Action 1

False = Action 2

Example:

Suppose, if your father promises you like if you got more than or equal to 90% marks, then, you are going to get the car otherwise nothing, so it will depends on your marks and your marks will be a variable that will set based on you exam result.

 

var examPercentage = 90;

If(examPercentage >= 90){ “You will get a car”}

else { “You will not get anything” }

Suppose, if your father also adds, you can also get a bike if you score more than 80%.

If(examPercentage >= 90){

“You will get a car”

} else if(examPercentage >= 80){

“You will get a bike”

} else {

“You will not get anything”

}

Variables

A variable is a symbolic name that you give reference to store any kind of information or value.

It’s value can also be changed.
Example:

In kitchen, there are different containers to store chilly and salt. And there is a label added on those containers that this container(say chillybox) is for chilly and this(saltbox) is for salt to identify them.
Same in programming, you can think variable name as container label.

Implementation:

var chillybox = “red chilly”

var saltbox = “salt”

But later, suppose, previously it was containing red chilly, but later, you want to replace it with green chilly.

chillybox = “green chilly”
So, you are updating chillybox variable from red chilly to green chilly.

Export div content to PDF using javascript

jquery code to generate pdf from div with automatic height and width –

Its can be easily done with html2canvas and jspdf. So, to generate pdf, first of all we have to include html2canvas and jspdf library.

For example –

Let’s say we have a div with id content and on a button(say Generate pdf) click, we want to export its content as a pdf.

First, write the code for creating button and include the required libraries(html2canvas and jspdf) –

<button id=”generatePDFbtn”>Generate PDF</div>
<div id=”content”>hello</div>
<script src=”https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js”></script>
<script src=”https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.5.0-beta4/html2canvas.min.js”></script>
<script src=”https://cdnjs.cloudflare.com/ajax/libs/jspdf/0.9.0rc1/jspdf.min.js”></script>
Then, create an event handler function to handle button click(Generate pdf button in our example) and write the code to generate the pdf –
<script>
$(document).on(“click”, “#generatePDFbtn”, function() {
        html2canvas(document.getElementById(“content”)).then(function(canvas) {
            var imgData = canvas.toDataURL(“image/jpeg”, 1.0);
            var pdf = new jsPDF(‘p’, ‘mm’, [400, 480]);
            pdf.addImage(imgData, ‘JPEG’, 0, 0, 400, 480);
            pdf.save(“search-result.pdf”);
        });
    });
</script>

For more related queries, please VISIT.

In case, if you did not find your solution or have any query/question, please contact us.

How to redirect http site to https using htaccess

Code to redirect http site to https using htaccess –

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</IfModule>

 

For more related queries, please visit.
In case, if you did not find your solution or have any query/question, please contact us.

How to change controller and model directory path in codeigniter ?

Change controller and model directory path(in Codeigniter) –

You can changed it by using HMVC extension.
First of all download the extension code from –
https://github.com/skjain5793/codeigniter-modular-extensions-hmvc

Extract it and
i.) put /third_party  folder files in application/third_party folder
ii.) put /core folder files in application/core folder

 

 

For more related queries, please visit.
In case, if you did not find your solution or have any query/question, please contact us.

Puzzles Interview Questions

Puzzles Interview Questions :

Ques: There are 3 persons in a room(say you and 2 others). From other 2 persons one speaks truth and another lies but you don’t know who speaks truth and who lies. There are 2 doors in the room(say door 1 and door 2) out of which 1 door opens. You have to ask only 1 question from 1 guy and have to find out which door opens.

 

For more related queries, please visit.
In case, if you did not find your solution or have any query/question, please contact us.

How to check that current page is a blog page in wordpress ?

Code to confirm that current page is a blog page in wordpress

Make a function in functions.php –
if(is_archive || is_author() || is_home() || is_single() || is_home() || is_tag() && post= ‘get_post_type’){
echo “this is a blog page”;
}

 

 

For more related queries, please visit.
In case, if you did not find your solution or have any query/question, please contact us.