JSFiddle - React, Tailwind, and code Playground

Accedo job interview test prototype 3

by Csaba Hellinger

HTML

<div ng-app="app">
    <div ng-controller="sumController">
        <div ng-show="!result" class="waiting">Waiting...</div>
        <div ng-show="result" class="result">Result: {{result}}</div>
    </div>
</div>

CSS

.waiting, .time {
    color: gray;
}

.result {
    font-size: 1.4em;
}

JavaScript

// Refactor the 'get' functionality (between the START and END comments) into a service.

angular.module('app', [])
	.controller('sumController', function sumController($scope, $q, $timeout) {

	// START ----------------------------------------------

	var data = {'a': 1, 'b': 2, 'c': 3};
    
    function get(key) {
        var deferred = $q.defer(),
            value = data[key];
        $timeout(function() {
            deferred.resolve(value);
        }, 100);
        return deferred.promise;
    }
    
	// END ----------------------------------------------
    
	var a, b, c;
	get('a')
    	.then(function (data) {
        	a = data;
            return get('b');
        })
    	.then(function (data) {
        	b = data;
            return get('c');
        })
    	.then(function (data) {
        	c = data;
            $scope.result = a + b + c;
        });
        
});