switched js total function