Skip to content

Instantly share code, notes, and snippets.

@LESTADru
Created May 9, 2014 15:47
Show Gist options
  • Save LESTADru/b37ef7429a5aecd777f0 to your computer and use it in GitHub Desktop.
Save LESTADru/b37ef7429a5aecd777f0 to your computer and use it in GitHub Desktop.
Объект с тремя методами запрашивает два значения, сохраняет их в свойства. Считает сумму и произведение этих чисел.
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
'Use Strict'
var calculator = {
readValues : function() {
this.value1 = +prompt("Enter first value", "0");
this.value2 = +prompt("Enter second value", "0")
},
sum : function() {
return this.value1 + this.value2;
},
mul : function() {
return this.value1 * this.value2;
}
}
calculator.readValues();
alert( calculator.sum() );
alert( calculator.mul() );
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment