Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <link href="https://fonts.googleapis.com/css2?family=Oswald:wght@300;500&display=swap" rel="stylesheet">
        <link rel="stylesheet" href="css/style.css">
        <title>COFFEE HOUSE</title>
    </head>
    <body>
        <div class="page">
            <header>
                <h1 class="header__h">Coffee house</h1>
            </header>
            
            <main>
               <div class="container">
                    <div class="main__top">
                        <input class="main__top__text" type="text" placeholder="Введите Фамилию" name="name">
                        <input class="main__top__text" type="text" placeholder="Введите Имя" name="surname">
                    </div>

                    <div class="main__center">
                        <div class="wrapper__main">
                           
                            <div class="wrapper__left">
                               
                                <div class="wrapper">
                                    <input class="wrapper__item" type="checkbox" id="espresso" name="price" value="espresso" data-price="80">
                                    <label class="wrapper__item" for="espresso"> Эспрессо 80р</label>
                                    <input class="wrapper__item" type="text" name="count" placeholder="0" value="0">
                                </div> <!-- wrapper -->
                                
                                <div class="wrapper">
                                    <input class="wrapper__item" type="checkbox" id="latte" name="price" value="latte" data-price="110">
                                    <label class="wrapper__item" for="latte">Латте 110р</label>
                                    <input class="wrapper__item" type="text" name="count" placeholder="0" value="0">
                                </div> <!-- wrapper -->
                                
                                <div class="wrapper">
                                    <input class="wrapper__item" type="checkbox" id="cappuccino" name="price" value="cappuccino" data-price="120">
                                    <label class="wrapper__item" for="cappuccino">Капучино 120р</label>
                                    <input class="wrapper__item" type="text" name="count" placeholder="0" value="0">
                                </div> <!-- wrapper -->
                                
                                <div class="wrapper">
                                    <input class="wrapper__item" type="checkbox" id="americano" name="price" value="americano" data-price="90">
                                    <label class="wrapper__item" for="americano">Американо 90р</label>
                                    <input class="wrapper__item" type="text" placeholder="0" name="count" value="0">
                                </div> <!-- wrapper -->
                                
                            </div> <!-- wrapper__left -->
                            
                            <div class="wrapper__right">
                                
                                <div class="wrapper">
                                    <input class="wrapper__item" type="checkbox" id="chocolate" name="price" value="chocolate" data-price="80">
                                    <label class="wrapper__item" for="chocolate">Шоколадный кекс 80р</label>
                                    <input class="wrapper__item" type="text" placeholder="0" name="count" value="0">
                                </div> <!-- wrapper -->
                                
                                <div class="wrapper">
                                    <input class="wrapper__item" type="checkbox" id="blueberry" name="price" value="blueberry" data-price="90">
                                    <label class="wrapper__item" for="blueberry">Черничный кекс 90р</label>
                                    <input class="wrapper__item" type="text" name="count" placeholder="0" value="0">
                                </div> <!-- wrapper -->
                                
                                <div class="wrapper">
                                    <input class="wrapper__item" type="checkbox" id="apple" name="price" value="apple" data-price="100">
                                    <label class="wrapper__item" for="apple">Яблочный торт 100р</label>
                                    <input class="wrapper__item" type="text" name="count" placeholder="0" value="0">
                                </div> <!-- wrapper -->
                                
                            </div> <!-- wrapper__right -->
                            
                        </div> <!-- wrapper__main --> 
                    </div> <!-- main__center -->

                    <div class="main__bottom">
                        <div class="wrapper__result">
                            <p class="result__item">Итого:</p>
                            <p class="result"></p>
                        </div>
                        <button class="btn">Оформить заказ</button>
                    </div>
                </div>
            </main>
            
        </div>
        <script src="js/main.js"></script>
    </body>
</html>
              
            
!

CSS

              
                html {
    font-size: 20px;
}

body {
    font-family: 'Oswald', sans-serif;
    font-size: 1rem;
    font-weight: 300;
    
    margin: 0;
}

*,
*:before,
*:after {
    box-sizing: border-box;
}

h1, h2, h3, h4, h5, h6 {
    margin: 0;
}

p {
    font-size: 1rem;
    font-weight: 300;
    color: #fff;
    margin: 0;
}

input {
    margin: 0;
}

.page {
    width: 100%;
    height: 100vh;
}

.container {
    width: 100%;
    max-width: 780px;
    
    margin: 0 auto;
}

/* Header */

header {
    padding: 30px 0;
}

.header__h {
    font-size: 1.8rem;
    font-weight: 500;
    text-transform: uppercase;
    text-align: center;
    color: #000;
}

/* Main */

main {
    width: 100%;
    padding: 85px 50px 35px 50px;
    
    background-color: #817070;
}

.main__top {
    display: flex;
    justify-content: center;
}

.main__top__text {
    font-size: 1rem;
    text-align: center;
    color: #fff;
    opacity: 1;
    background-color: #817070;
    border: 3px solid #fff;
    padding: 12px 30px 10px 30px;
}

.main__top__text::placeholder {
    font-size: 1rem;
    text-align: center;
    color: #fff;
    opacity: 0.8;
    text-transform: capitalize;
}

.main__top__text:nth-child(n + 2) {
    margin-left: 64px;
}

/* Main__center */

.main__center {
    margin-top: 84px;
    margin-bottom: 40px;
}

.wrapper {
    display: flex;
    align-items: center;
}

.wrapper:nth-last-child(n + 2) {
    margin-bottom: 17px;
}

.wrapper__item:nth-child(1) {
    flex-basis: 10%;
}

.wrapper__item:nth-last-child(1) {
    width: 130px;
    height: 50px;
    padding: 12px 40px 10px 40px;
    
    font-size: 1rem;
    font-weight: 300;
    color: #fff;
    text-align: center;
    border: 3px solid #fff;
    background-color: #817070;
    
    flex-basis: 30%;
    
}

.wrapper__item:nth-last-child(1)::placeholder {
    color: #fff;
    opacity: 0.8;
}

.wrapper__item:nth-child(2) {
    font-size: 1rem;
    font-weight: 300;
    color: #fff;
    
    flex-basis: 60%;
    
}

.wrapper__main {
    display: flex;
}

.wrapper__left {
    flex-basis: 50%;
    padding: 0 50px 0 25px;
}

.wrapper__right {
    flex-basis: 50%;
    
    padding: 0 10px 0 15px;
}

.main__bottom {
    padding-bottom: 35px;
    text-align: center;
}

.wrapper__result {
    display: inline-flex;
    justify-content: space-between;
    width: 90px;
    margin-bottom: 25px;
}

.result {
    margin-left: 5px;
}

.btn {
    display: block;
    width: 200px;
    height: 65px;
    margin: 0 auto;
    padding: 12px 20px;
    
    font-family: 'Oswald', sans-serif;
    font-size: 1rem;
    font-weight: 500;
    color: #817070;
    text-transform: uppercase;
    text-align: center;
}

.result__item {
}

















              
            
!

JS

              
                checkboxElements = document.querySelectorAll('[name="price"]');
countElements = document.querySelectorAll('[name="count"]');
resultElement = document.querySelector('.result');


let selectedContactValues = [];

function sumArray(arr) {
    let sum = 0;
    arr.forEach(function(item, i, arr) {
      sum += arr[i];
  });
    return sum;
};

checkboxElements.forEach(function(item, i, arr) {
    item.addEventListener('change', function() {
     if(item.checked) {
         selectedContactValues.push(parseInt(item.dataset.price));
         countElements[i].value = 1;
     } else {
         selectedContactValues.splice(selectedContactValues.indexOf(item.dataset.price),1);
         countElements[i].value = 0;
     }
        
        resultElement.textContent =  sumArray(selectedContactValues);
    });
});

              
            
!
999px

Console