"JS10 Day 4: Create a Rectangle Object"의 두 판 사이의 차이

(새 문서: ==개요== ;<nowiki>JS10 Day 4: Create a Rectangle Object</nowiki> * https://www.hackerrank.com/challenges/js10-throw/problem <source lang='javascript'> 'use strict'; process.stdin....)
 
1번째 줄: 1번째 줄:
==개요==
==개요==
;<nowiki>JS10 Day 4: Create a Rectangle Object</nowiki>
;<nowiki>JS10 Day 4: Create a Rectangle Object</nowiki>
* https://www.hackerrank.com/challenges/js10-throw/problem
* https://www.hackerrank.com/challenges/js10-objects/problem


<source lang='javascript'>
<source lang='javascript'>

2018년 8월 12일 (일) 14:11 판

1 개요

JS10 Day 4: Create a Rectangle Object
'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    
    main();    
});

function readLine() {
    return inputString[currentLine++];
}
/*
 * Complete the Rectangle function
 */
function Rectangle(a, b) {
    this.length = a;
    this.width = b;
    this.perimeter = 2 * (a+b);
    this.area = a * b;
}
function main() {
    const a = +(readLine());
    const b = +(readLine());
    
    const rec = new Rectangle(a, b);
    
    console.log(rec.length);
    console.log(rec.width);
    console.log(rec.perimeter);
    console.log(rec.area);
}

2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}