Here, what I am doing is printing my javascript code by wrapping between "pre" tags like this :
<pre>
var sum = function(toSum) {
var j = 0;
for(var i=0; i<toSum.length; i++) {
j = j + toSum[i];
}
console.log("The sum of array is " + j);
};
sum([1,2,3,4]);
var multiply = function(toMultiply) {
var j = 1;
for(var i=0; i<toMultiply.length; i++) {
j = j * toMultiply[i];
}
console.log("The multiplication of array is " + j);
};
multiply([1,2,3,4]);
</pre>
But what I am actual getting is this :
var sum = function(toSum) {
var j = 0;
for(var i=0; i
Why is that so? How can I get "pre" tag working?
You should use <
instead of <
.
Similarly, use >
for >
and &
for &
when displaying in HTML.
Your for loop will be like:
for(var i=0; i<toSum.length; i++) {
...
}