I am grappling with the task of verifying whether my variable only contains a single character.
The approach I have taken involves:
var n = new Date();
$scope.h = n.getHours();
$scope.m = n.getMinutes();
console.log($scope.h.length) // returns undefined
if($scope.h.length < 2 && $scope.m.length < 2 ) {
$scope.hm = $scope.h * 10 + "" + $scope.m * 10;
console.log($scope.hm);
}
However, the issue arises when $scope.h.length yields undefined. The question is - why does this happen? How can I improvise on this method?