Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Parašykite, funkcijų spausdinamas arba gražinamas reikšmes
- /*
- Užduotis 1
- */
- function test() {
- console.log(a);
- console.log(foo());
- var a = 1;
- function foo() {
- return 2;
- }
- }
- test();
- /*
- Užduotis 2
- */
- function darytiKazka(string) {
- var newStr = "";
- for (var i = string.length - 1; i >= 0; i--) {
- newStr += string[i];
- }
- return newStr;
- }
- var rezultatas = darytiKazka(“dog”);
- console.log(rezultatas);
- /*
- Užduotis 3
- */
- function geriausiaFunkcija(a) {
- var geras = a[0];
- for (var i = 1; i < a.length; i += 1) {
- if (a[i] > geras) {
- geras = a[i];
- }
- }
- return geras;
- };
- geriausiaFunkcija([5,10, 100, 12, 2]);
- /*
- Užduotis 4
- */
- function calculateSupply(age, numPerDay) {
- var maxAge = 100;
- var totalNeeded = (numPerDay * 365) * (maxAge - age);
- var message = 'You will need ' + totalNeeded + ' cups of tea to last you until the ripe old age of ' + maxAge;
- console.log(message);
- }
- calculateSupply(28, 36);
- /*
- Užduotis 5
- */
- function amountTocoins(amount, coins)
- {
- if (amount === 0)
- {
- return [];
- }
- else
- {
- if (amount >= coins[0])
- {
- left = (amount - coins[0]);
- return [coins[0]].concat( amountTocoins(left, coins) );
- }
- else
- {
- coins.shift();
- return amountTocoins(amount, coins);
- }
- }
- }
- console.log(amountTocoins(46, [25, 10, 5, 2,1]));
- http://www.w3resource.com/javascript-exercises/javascript-function-exercise-14.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement