vladovip

JavaScript -PyramindKingDjaser_exercise _ Basic Syntax_ Conditional statements

Dec 19th, 2021
994
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Pyramid(base, increment) {
  2.  
  3.     let totalstone = 0;
  4.     let totalmarble = 0;
  5.     let totallapis = 0;
  6.     let totalgold = 0;
  7.     let row = 0;
  8.     let currentbase = base;
  9.  
  10.     while (currentbase > 2) {
  11.         let marbel = currentbase * 4 - 4;
  12.         let stone = currentbase * currentbase - marbel;
  13.         totalstone += stone;
  14.         row++;
  15.         if (row % 5 === 0) {
  16.             totallapis += marbel;
  17.         } else {
  18.             totalmarble += marbel;
  19.         }
  20.         currentbase -= 2;
  21.     }
  22.     row++;
  23.    
  24.     let gold = currentbase * currentbase;
  25.  
  26.     stone = Math.ceil(totalstone * increment);
  27.     marble = Math.ceil(totalmarble * increment);
  28.     lapis = Math.ceil(totallapis * increment);
  29.     totalgold = Math.ceil(gold * increment);
  30.     totalHeight = Math.floor(row * increment);
  31.  
  32.     console.log(`Stone required: ${stone}`);
  33.     console.log(`Marble required: ${marble}`);
  34.     console.log(`Lapis Lazuli required: ${lapis}`);
  35.     console.log(`Gold required: ${totalgold}`);
  36.     console.log(`Final pyramid height: ${totalHeight}`);
  37.  
  38. }
  39. Pyramid(11, 1);
  40.  
Advertisement
Add Comment
Please, Sign In to add comment