Prog W Javascript Coursera Ans
Prog W Javascript Coursera Ans
Prog W Javascript Coursera Ans
iteration
// Task 1
// Task 2
// Task 3
var dairy = ['cheese', 'sour cream', 'milk', 'yogurt', 'ice cream', 'milkshake'];
function logDairy() {
console.log(item);
logDairy();
const animal = {
canJump: true
};
bird.canFly = true;
bird.hasFeathers = true;
function birdCan() {
for (let key in bird) {
if (bird.hasOwnProperty(key)) {
console.log(`${key}: ${bird[key]}`);
birdCan();
function animalCan() {
console.log(`${key}: ${bird[key]}`);
animalCan();
function timesTwo(number) {
return number * 2;
module.exports = timesTwo;
timesTwo.test.js
const timesTwo = require('./timesTwo');
expect(timesTwo(10)).toBe(20);
});
Package.json
"name": "jest-testing",
"version": "1.0.0",
"description": "",
"main": "timesTwo.js",
"scripts": {
"test": "jest"
},
"devDependencies": {
"jest": "^28.0.0"
// Updated dish data to match the expected output from the test cases
const dishData = [
];
let finalPrice;
finalPrice = dish.price;
} else {
return;
// Function to apply discounts based on guest count and print the final output
getPrices(taxBoolean);
if (typeof guests === 'number' && guests > 0 && guests < 30) {
let discount = 0;
if (guests < 5) {
discount = 5;
discount = 10;
}
console.log("Discount is: $" + discount);
} else {