My node.js code is below.
Basically I have a buffer called searchRes and first I get some values from it.
It is supposed to loop round "results - 1" times.
It is looping.
It prints the first 3 bits of information totally correctly and then after that (4th onwards) is always the same as the 3rd one.
I have no idea why.
results = 20;
var sSize = searchRes.slice(8,16);
sSize = parseInt(sSize,16);
lols = new Array();
while(num <= results -1 ){
var cur = num + 1;
var sres=0;
for(var i in lols) { sres += lols[i]; }
if (num == 0){
var clanRes = searchRes.slice(0, 128 + (sSize * 2));
var cLen = clanRes.slice(8,16);
cLen = parseInt(cLen,16);
var firstLen = clanRes.length;
var lastLen = clanRes.length;
}else{
var cLen = searchRes.slice(lastLen + 8, lastLen + 16);
cLen = parseInt(cLen,16);
var clanRes = searchRes.slice(
lastLen,
lastLen + 128 + (cLen * 2)
);
var abc = 1;
if (abc == 1){
var lastLen = firstLen + clanRes.length;
abc++;
}else{
var lastLen = lastLen + clanRes.length;
}
}
lols.push(cLen);
console.log('\n\nClan ' + cur + ' Details');
var clanID = clanRes.slice(0,8);
clanID = parseInt(clanID,16);
num ++;
}
I'm not sure at all about where the problem is. Is it when defining clanRes or is it in making the loop?
Thanks!
**
Updated code for #bergi
**
num = 0;
var sSize = searchRes.slice(8,16);
sSize = parseInt(sSize,16);
lols = new Array();
while(num <= 3){
var cur = num + 1;
var sres=0;
for(var i in lols) { sres += lols[i]; }
if (num == 0){
var clanRes = searchRes.slice(0, 128 + (sSize * 2));
var cLen = clanRes.slice(8,16);
cLen = parseInt(cLen,16);
var firstLen = clanRes.length;
var lastLen = clanRes.length;
}else{
var cLen = searchRes.slice(lastLen + 8, lastLen + 16);
cLen = parseInt(cLen,16);
var clanRes = searchRes.slice(
lastLen,
lastLen + 128 + (cLen * 2)
);
var abc = 1;
if (abc == 1){
var lastLen = firstLen + clanRes.length;
abc++;
}else{
var lastLen = lastLen + clanRes.length;
}
}
lols.push(cLen);
console.log('\n\nClan ' + cur + ' Details');
var clanID = clanRes.slice(0,8);
clanID = parseInt(clanID,16);
console.log(clanID);
num ++;
}
Here is a exmaple searchRes:
http://pastie.org/10075399
And an example sSize:
0000000e - hex
14 - int.
var abc = 1;
if (abc == 1){
abc is always 1 in that comparison (the value is assigned right in the line before), so it will never evaluate the else block. I assume you want to move the initialisation of the variable out of the looping.
Related
i want to display TravelTimeHoursDiff and TravelTimeMinutesDiff in double digit now my time is shown as 7:0 i want to display like 07:00
if ($scope.DispatchStatus.ArrivalTime != undefined){
var today = $rootScope.getSysDate().split(" ");
var timeArrival = new Date(today[0] + ' ' + $scope.DispatchStatus.ArrivalTime);
var TravelTime = new Date(today[0] + ' ' + $scope.Route.TravelTime);
var timeArrivalHours = timeArrival.getHours();
var TravelTimeHoursDiff = timeArrivalHours - TravelTime.getHours() ;
var TravelTimeMinutesDiff = (timeArrival.getMinutes() - TravelTime.getMinutes());
if(TravelTimeHoursDiff < 0 || (TravelTimeHoursDiff <= 0 && TravelTimeMinutesDiff < 0) || (TravelTimeHoursDiff == 0 && TravelTimeMinutesDiff == 0)){
$scope.formvalidationbit = $scope.DispatchStatusAddForm[fieldName].$invalid = true;
angular.element('#' + fieldName).addClass('ng-invalid');
angular.element('#' + fieldName).removeClass('ng-valid');
$scope.DispatchStatusAddForm.$valid = false;
var errorbit = 1;
}else{
if (isNaN(TravelTimeHoursDiff)) {
TravelTimeHoursDiff = '--';
}
if (isNaN(TravelTimeMinutesDiff)) {
TravelTimeMinutesDiff = '--';
}
if(TravelTimeMinutesDiff <0){
TravelTimeMinutesDiff = TravelTimeMinutesDiff * (-1);
}
$scope.TravelTime = TravelTimeHoursDiff + ':' + TravelTimeMinutesDiff;
}
}
Just add leading 0 to values smaller then 10, something like:
let addLeadingZero(v){
return v < 10 ? ("0" + v) : v;
}
$scope.TravelTime = addLeadingZero(TravelTimeHoursDiff) + ':' + addLeadingZero(TravelTimeMinutesDiff);
Can somebody please tell me what is wrong with the JavaScript in this code? It said "Unexpected end of input", but I do not see any errors. All my statements seem to be ended at some point, and every syntax checker says that no errors were detected.
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<title>Slide Editor</title>
<style>
#font-face {
font-family: SegoeUILight;
src: url(Segoe_UI_Light.ttf);
}
* {
font-family: SegoeUILight;
}
</style>
<script src="Slide/RevealJS/lib/js/html5shiv.js"></script>
<script src="Slide/RevealJS/lib/js/head.min.js"></script>
</head>
<body onload="editSlideshow()">
<div id="sl">
<span id="sls"></span>
</div>
<span id="slt"></span>
<div id="editor">
</div>
<script>
function getURLParameters(paramName) {
var sURL = window.document.URL.toString();
if (sURL.indexOf("?") > 0) {
var arrParams = sURL.split("?");
var arrURLParams = arrParams[1].split("&");
var arrParamNames = new Array(arrURLParams.length);
var arrParamValues = new Array(arrURLParams.length);
var i = 0;
for (i = 0; i < arrURLParams.length; i++) {
var sParam = arrURLParams[i].split("=");
arrParamNames[i] = sParam[0];
if (sParam[1] != "")
arrParamValues[i] = unescape(sParam[1]);
else
arrParamValues[i] = "No Value";
}
for (i = 0; i < arrURLParams.length; i++) {
if (arrParamNames[i] == paramName) {
//alert("Parameter:" + arrParamValues[i]);
return arrParamValues[i];
}
}
return "No Parameters Found";
}
}
var name = getURLParameters("show");
var slideCount = 1;
function editSlideshow() {
if (localStorage.getItem("app_slide_doc_" + name) == null) {
$("#sls").append('<button onclick = "loadSlide\'1\')" id = "slide_1">Slide 1</button>');
$("#sl").append('button onclick = "newSlide()">New Slide</button>');
slideCount = 1;
} else {
var textArray = JSON.parse(localStorage.getItem("app_slide_doc_" + name));
slideCount = textArray.length;
var slideCnt = textArray.length - 1;
for (var i = 0; i <= slideCnt; i++) {
$("#sls").append('<button onclick = "loadSlide\'' + (i + 1) + '\')" id = "slide_' + (i + 1) + '">Slide ' + (i + 1) + '</button>');
};
$("sl").append('<button onclick = "newSlide()">New Slide</button>');
};
};
function loadSlide(num) {
var array = JSON.parse(localStorage.getItem("app_slide_doc_" + name));
if (array == null) {
document.getElementById("editor").innerHTML = "<p><textarea rows = '15' cols = '100' id = 'editTxt'></textarea></p>";
document.getElementById("slt").innerHTML = "Slide " + num;
$("#editor").append("<p><button onclick = 'saveSlide(\"" + num + "\")'>Save Slide</button><button onclick = 'deleteSlide(\"" + num + "\")'>Delete Slide</button></p>");
} else if (array[num - 1] == null) {
document.getElementById("editor").innerHTML = "<p><textarea rows = '15' cols = '100' id = 'editTxt'></textarea></p>";
document.getElementById("slt").innerHTML = "Slide " + num;
$("#editor").append("<p><button onclick = 'saveSlide(\"" + num + "\")'>Save Slide</button><button onclick = 'deleteSlide(\"" + num + "\")'>Delete Slide</button></p>");
} else {
var slideArray = JSON.parse(localStorage.getItem("app_slide_doc_" + name));
var text = slideArray[num - 1];
document.getElementById("editor").innerHTML = "<p><textarea rows = '15' cols = '100' id = 'editTxt'></textarea></p>";
document.getElementById("editTxt").value = text;
document.getElementById("slt").innerHTML = "Slide " + num;
$("#editor").append("<p><button onclick = 'saveSlide(\"" + num + "\")'>Save Slide</button><button onclick = 'deleteSlide(\"" + num + "\")'>Delete Slide</button></p>");
};
};
function saveSlide(num) {
if (localStorage.getItem("app_slide_doc_" + name) == null) {
var text = document.getElementById("editTxt").value;
var textArray = new Array();
textArray[num - 1] = text;
localStorage.setItem("app_slide_doc_" + name, JSON.stringify(textArray));
} else {
var textArray = JSON.parse(localStorage.getItem("app_slide_doc_" + name));
var text = document.getElementById("editTxt").value;
textArray[num - 1] = text;
localStorage.setItem("app_slide_doc_" + name, JSON.stringify(textArray));
};
};
function newSlide() {
var nextSlide = slideCount + 1;
$("#sls").append('<button onclick = "loadSlide(\'' + nextSlide + '\')" id = "slide_' + nextSlide.toString() + '">Slide ' + nextSlide.toString() + '</button>');
slideCount = nextSlide;
};
function deleteSlide(num) {
if (localStorage.getItem("app_slide_doc_" + name) == null) {
if (num !== "1") {
$("#slide_" + num).remove();
document.getElementById("editor").innerHTML = "";
document.getElementById("slt").innerHTML = "";
slideCount = slideCount - 1;
location.reload();
} else {
alert("The first slide cannot be deleted.");
};
} else {
var textArray = JSON.parse(localStorage.getItem("app_slide_doc_" + name));
if (num !== "1") {
$("#slide_" + num).remove();
document.getElementById("editor").innerHTML = "";
document.getElementById("slt").innerHTML = "";
slideCount = slideCount - 1;
textArray.splice((num - 1), 1);
localStorage.setItem("app_slide_doc_" + name, JSON.stringify(textArray));
location.reload();
} else {
alert("The first slide cannot be deleted.");
};
};
};
</script>
</body>
</html>
You've gotten the punctuation wrong in more than one of your onclick attributes, for instance here:
$("#sls").append('<button onclick = "loadSlide\'1\')" id = "slide_1">Slide 1</button>');
It's missing the opening parenthesis. The reason syntax checks don't immediately catch this is because you're putting code inside a string. Which you should not do.
Since you're using jQuery, how about using .click(function() { ... }) instead of inline attributes? Just be careful to get your captured variables correct.
The problem at line 63
$("#sl").append('button onclick = "newSlide()">New Slide</button>');
Should be:
$("#sl").append('<button onclick = "newSlide()">New Slide</button>');
I am stuck trying to convert a javascript file that ran perfectly in d6 to d7, I have been searching through the info about drupal behaviours but cannot seem to find the correct manner to resolve this.
The following script returns an unexpected token error ), for the closing bracket before (jQuery).
(function($){
var VAT = 0.2;
var QUANTITY_SUFFIX = "field-po-quantity";
var PRICE_SUFFIX = "field-po-price";
var SUBTOTAL_SUFFIX = "field-po-item-st";
var VAT_SUFFIX = "field-po-item-vat";
var TOTAL_SUFFIX = "field-po-item-total";
var quantityFields;
var priceFields;
var fieldsValid = false;
function isNumber(value) {
return !isNaN(parseFloat(value)) &&
isFinite(value);
}
function validValue(value) {
return isNumber(value) &&
parseFloat(value) > 0;
}
function addCommas(nStr) {
nStr += '';
var x = nStr.split('.');
var x1 = x[0];
var x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
function decimalise(value) {
if (isNumber(value)) {
var numericValue = parseFloat(value);
return numericValue.toFixed(2);
}
}
function validateFields() {
var fieldsValid = true;
var allFields = new Array();
quantityFields = jQuery('input[id*="' + QUANTITY_SUFFIX + '"]');
priceFields = jQuery('input[id*="' + PRICE_SUFFIX + '"]');
allFields.push.apply(allFields, quantityFields);
allFields.push.apply(allFields, priceFields);
for (i=0; i<allFields.length; i++) {
var field = allFields[i];
var valueString = field.value;
if (!validValue(valueString)) {
field.style.borderStyle="solid";
field.style.border="inset 1px red";
fieldsValid = false;
} else {
field.style.borderStyle="none";
}
}
this.fieldsValid = fieldsValid;
}
jQuery(document).click(function() {
validateFields();
if (fieldsValid) {
var subTotalSum = 0;
var vatSum = 0;
var totalSum = 0;
jQuery('#field-po-items-values tbody tr:not(.content-multiple-removed-row)').each(function(){
var quantityString = jQuery(this).find('input[id*="' + QUANTITY_SUFFIX + '"]').val();
var numericQuantity = decimalise(quantityString);
var priceString = jQuery(this).find('input[id*="' + PRICE_SUFFIX + '"]').val();
var numericPrice = decimalise(priceString);
var subtotal = parseFloat(numericPrice * numericQuantity);
jQuery(this).find('input[id*="' + SUBTOTAL_SUFFIX + '"]').val(addCommas(decimalise(subtotal)));
var vat = subtotal * VAT;
jQuery(this).find('input[id*="' + VAT_SUFFIX + '"]').val(addCommas(decimalise(vat)));
var total = subtotal + vat;
jQuery(this).find('input[id*="' + TOTAL_SUFFIX + '"]').val(addCommas(decimalise(total)));
subTotalSum += subtotal;
vatSum += vat;
totalSum += parseFloat(total);
});
jQuery('input[id*="edit-field-po-subtotal"]').val(addCommas(decimalise(subTotalSum)));
jQuery('input[id*="edit-field-po-vat"]').val(addCommas(decimalise(vatSum)));
jQuery('input[id*="edit-field-po-total"]').val(addCommas(decimalise(totalSum)));
}
}
})(jQuery);
The file is being called from template.php, using drupal_add_js inserted in the top of the file, not under pre-process or anything.
I understand that the jQuery(document).click(function() { might also be causing an issue and may ultimately be the reason for the unexpected token error?
Thank you in advance
I don`t know whether your code is correct but it is highly recommended to use JavaScript in Drupal>7 this way:
(function ($) {
Drupal.behaviors.yourFunction = {
attach: function(context, settings) {
var VAT = 0.2;
var QUANTITY_SUFFIX = "field-po-quantity";
var PRICE_SUFFIX = "field-po-price";
var SUBTOTAL_SUFFIX = "field-po-item-st";
var VAT_SUFFIX = "field-po-item-vat";
var TOTAL_SUFFIX = "field-po-item-total";
var quantityFields;
var priceFields;
var fieldsValid = false;
function isNumber(value) {
return !isNaN(parseFloat(value)) &&
isFinite(value);
}
function validValue(value) {
return isNumber(value) &&
parseFloat(value) > 0;
}
function addCommas(nStr) {
nStr += '';
var x = nStr.split('.');
var x1 = x[0];
var x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
function decimalise(value) {
if (isNumber(value)) {
var numericValue = parseFloat(value);
return numericValue.toFixed(2);
}
}
function validateFields() {
var fieldsValid = true;
var allFields = new Array();
quantityFields = $('input[id*="' + QUANTITY_SUFFIX + '"]');
priceFields = $('input[id*="' + PRICE_SUFFIX + '"]');
allFields.push.apply(allFields, quantityFields);
allFields.push.apply(allFields, priceFields);
for (i=0; i<allFields.length; i++) {
var field = allFields[i];
var valueString = field.value;
if (!validValue(valueString)) {
field.style.borderStyle="solid";
field.style.border="inset 1px red";
fieldsValid = false;
} else {
field.style.borderStyle="none";
}
}
this.fieldsValid = fieldsValid;
}
$(document).click(function() {
validateFields();
if (fieldsValid) {
var subTotalSum = 0;
var vatSum = 0;
var totalSum = 0;
$('#field-po-items-values tbody tr:not(.content-multiple-removed-row)').each(function(){
var quantityString = $(this).find('input[id*="' + QUANTITY_SUFFIX + '"]').val();
var numericQuantity = decimalise(quantityString);
var priceString = $(this).find('input[id*="' + PRICE_SUFFIX + '"]').val();
var numericPrice = decimalise(priceString);
var subtotal = parseFloat(numericPrice * numericQuantity);
$(this).find('input[id*="' + SUBTOTAL_SUFFIX + '"]').val(addCommas(decimalise(subtotal)));
var vat = subtotal * VAT;
$(this).find('input[id*="' + VAT_SUFFIX + '"]').val(addCommas(decimalise(vat)));
var total = subtotal + vat;
$(this).find('input[id*="' + TOTAL_SUFFIX + '"]').val(addCommas(decimalise(total)));
subTotalSum += subtotal;
vatSum += vat;
totalSum += parseFloat(total);
});
$('input[id*="edit-field-po-subtotal"]').val(addCommas(decimalise(subTotalSum)));
$('input[id*="edit-field-po-vat"]').val(addCommas(decimalise(vatSum)));
$('input[id*="edit-field-po-total"]').val(addCommas(decimalise(totalSum)));
}
}
}
};
})(jQuery);
More info about Drupal Behaviours:
Drupal behaviors
Theming, jQuery, DRupal Behaviours
I have this pagination script which works perfectly except for this little issue.
so now I want to limit the navigation numbers.
but I can't pass the (this.currentPage)
window.thisPager= new Pager('comments', 10);
thisPager.init();
thisPager.showPageNav('thisPager', 'pageNavPosition');
thisPager.showPage(1);
function Pager(class_name, itemsPerPage) {
this.class_name = class_name;
this.itemsPerPage = itemsPerPage;
this.currentPage = pageNumber;
this.pages = 0;
this.inited = true;
this.showRecords = function(from, to) {
var rows = $('.' + class_name);
for (var i = 0; i < rows.length; i++) {
if (i < from || i > to)
rows[i].style.display = 'none';
else
rows[i].style.display = '';
}
}
this.showPage = function(pageNumber) {
if (! this.inited) {
alert("not inited");
return;
}
var oldPageAnchor = document.getElementById('pg'+this.currentPage);
oldPageAnchor.className = 'pg-normal';
this.currentPage = pageNumber;
var newPageAnchor = document.getElementById('pg'+this.currentPage);
newPageAnchor.className = 'pg-selected';
var from = (pageNumber - 1) * itemsPerPage;
var to = from + itemsPerPage - 1;
this.showRecords(from, to);
}
this.prev = function() {
if (this.currentPage > 1)
this.showPage(this.currentPage - 1);
}
this.next = function() {
if (this.currentPage < this.pages) {
this.showPage(this.currentPage + 1);
}
}
this.last = function() {
if (this.currentPage < this.pages) {
this.showPage(this.pages);
}
}
this.first = function() {
if (this.currentPage > 1) {
this.showPage(1);
}
}
this.init = function() {
var rows = $('.' + class_name);
var records = (rows.length);
this.pages = Math.ceil(records / itemsPerPage);
this.inited = true;
}
this.showPageNav = function(pagerName, positionId) {
if (! this.inited) {
alert("not inited");
return;
}
var element = document.getElementById(positionId);
var pagerHtml = '<span onClick="'+pagerName+'.first();" class="pg-normal"> « First</span>';
pagerHtml += '<span onClick="' + pagerName + '.prev();" class="pg-normal"> « Prev </span> | ';
for (var page = 1; page <= this.currentpages; page++)
pagerHtml += '<span id="pg' + page + '" class="pg-normal" onClick="' + pagerName + '.showPage(' + page + ');">' + page + '</span> | ';
pagerHtml += '<span onClick="'+pagerName+'.next();" class="pg-normal"> Next »</span>';
pagerHtml += '<span onClick="'+pagerName+'.last();" class="pg-normal"> Last »</span>';
element.innerHTML = pagerHtml;
}
}
Please follow this link
http://jsfiddle.net/J3Qnx/16/
I'm trying to pass this.currentPage into this
for (var page = 1; page <= this.currentpage + 5; page++)
but it's not working as I expected
please help guys
It looks like this is an issue of using the wrong case. It looks like you're using currentPage throughout your script but your trying to call currentpage in the for loop. Try fixing the case and see if that works.
var class_name = "comments";
var rows = $('.' + class_name);
var itemsPerPage = 10;
var currentPage = 1;
var inited = false;
var pagerName = "thisPager";
var positionId = "pageNavigation";
var records = $('.' + class_name).length;
var pages = Math.ceil(records / itemsPerPage);
showRecords(0, 9);
navigator(currentPage, positionId, pages);
function showRecords(from, to){
for (var i = 0; i < rows.length; i++) {
if (i < from || i > to)
rows[i].style.display = 'none';
else
rows[i].style.display = '';
}}
function showPage(pageNumber) {
currentPage = pageNumber;
var from = (currentPage - 1) * itemsPerPage;
var to = from + itemsPerPage - 1;
var positionId = "pageNavigation";
var records = $('.' + class_name).length;
var pages = Math.ceil(records / itemsPerPage);
showRecords(from, to, rows);
navigator(currentPage, positionId, pages);
var oldPageAnchor = document.getElementById('pg'+pageNumber);
oldPageAnchor.className = "pg-selected";
}
function navigator(currentPage, positionId, pages){
var element = document.getElementById(positionId);
var pagerHtml = '';
for (var page = currentPage - 4; page <= currentPage + 4; page++)
if (page >= 1)
if (page <= pages)
pagerHtml += '<span id="pg' + page + '" class="pg-normal" onClick="showPage(' + page + ');">' + page + '</span> | ';
element.innerHTML = pagerHtml;
}
I'm kind of new to Javascript, and somebody helped me with this script, it works great on Chrome but it doesn't work in Firefox, and haven't tested it in IE yet but I want it to work in all browsers, and I don't really know that much on jQuery as to translate it
function displayTotal()
{
var tableRows = document.getElementById('budgetTable').getElementsByTagName('tr');
var totalDays = tableRows.length - 3; //Don't count the header rows and the Total rows
var totalPrice = 0;
var price = filterNum(document.getElementById( 'txtPrice' ).value);
var totalField = document.getElementById('txtTotal');
var tempHours = 0;
var tempTotal = 0;
for(var i = 0; i < totalDays; i++)
{
tempHours = document.getElementById("end" + i).value - document.getElementById("start" + i).value;
tempTotal = tempHours * price;
document.getElementById("total" + i).innerHTML = formatCurrency(tempTotal);
totalPrice += tempTotal;
console.log(i, "Start:" + document.getElementById("start" + i).value, "End:" + document.getElementById("end" + i).value, "Hours:" + tempHours, "Total:" + tempTotal);
}
totalField.value = formatCurrency(totalPrice);
}
function addRowToTable()
{
var tbl = document.getElementById('budgetTable');
var lastRow = tbl.rows.length - 2;
var iteration = lastRow;
var entry = iteration - 1; //because we started with day0, etc
var row = tbl.insertRow(lastRow);
// day cell
var cellDay = row.insertCell(0);
cellDay.appendChild(createInput('text','day' + entry, '', displayTotal));
// start cell
var cellStart = row.insertCell(1);
cellStart.appendChild(createInput('text','start' + entry, 0, displayTotal));
// end cell
var cellEnd = row.insertCell(2);
cellEnd.appendChild(createInput('text','end' + entry, 0, displayTotal));
// total cell
var cellTotal = row.insertCell(3);
cellTotal.id = 'total' + entry;
}
function createInput(type, id, value, action)
{
var el = document.createElement('input');
el.type = type;
el.id = id;
el.value = value;
el.onkeyup = action;
return el;
}
function filterNum(str)
{
re = /^\$|,/g;
// remove "$" and ","
return str.replace(re, "");
}
function formatCurrency(num)
{
num = isNaN(num) || num === '' || num === null ? 0.00 : num;
return parseFloat(num).toFixed(2);
}
Any help will be welcomed as I really don't know where I'm missing then point here.
EDIT: ok, this is weird, but on Firefox, when I enable firebug to try to debug it,... it works.
tempHours = document.getElementById("end" + i).value - document.getElementById("start" + i).value;
document.getElementById("total" + i).innerHTML
The output any element attribute (such as element.value and element.innerHTML) is always a string. You can only perform mathematical functions on numbers. If the string only contains 'number characters' you can use parseInt() or parseFloat to convert them
console.log(); // Is a Firebug function. Try commenting it out.