Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bfcd362

Browse files
committed
Shopping-exe4 as exercise 4 added - noer-ex1 is modified and the soloution has changed
1 parent ef40c9d commit bfcd362

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
'use strict'
2+
const compliments = ["great", "amazing", "wonderful", "lamentable", "attractive", "merciful", "fair" , "spectacular", "dynamic", "elegant"];
23
function giveCompliment(name) {
3-
const compliments = ["great", "amazing", "wonderful", "lamentable", "attractive", "merciful", "fair" , "spectacular", "dynamic", "elegant"];
4+
45
const randCompliment = compliments[Math.floor(Math.random() * compliments.length)];
5-
6-
return `You are ${randCompliment}, ${name}!`; //I've tried to use "return" without console.log but it didn't return anything! Why?
6+
const result = console.log(`You are ${randCompliment}, ${name}!`)
7+
return result; //I've tried to use "return" without console.log but it didn't return anything! Why?
78
};
8-
// giveCompliment('ali')
9-
const x = giveCompliment('ali');
10-
const y = giveCompliment('ali');
11-
const z = giveCompliment('ali');
12-
console.log(x);
13-
console.log(y);
14-
console.log(z);
9+
giveCompliment('ali')
10+
// const x = giveCompliment('ali');
11+
// const y = giveCompliment('ali');
12+
// const z = giveCompliment('ali');
13+
// console.log(x);
14+
// console.log(y);
15+
// console.log(z);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict'
2+
const shoppingCart = ['bananas', 'milk'];
3+
function addToShoppingCart(item){
4+
shoppingCart.push(item);
5+
for(let i = 0; i < shoppingCart.length; i++) {
6+
if (shoppingCart.length > 3) {
7+
shoppingCart.shift();
8+
}
9+
};
10+
const result = console.log(`You bought ${shoppingCart}!`)
11+
return result;
12+
};
13+
addToShoppingCart('chocolate');
14+
addToShoppingCart('waffles');
15+
addToShoppingCart('tea');

0 commit comments

Comments
 (0)