Skip to content

Instantly share code, notes, and snippets.

@momota10s
Last active August 29, 2015 14:21
Show Gist options
  • Save momota10s/0f3347671bc838e9191b to your computer and use it in GitHub Desktop.
Save momota10s/0f3347671bc838e9191b to your computer and use it in GitHub Desktop.
JavaScriptの基礎
//var
var example = 'some string';
//console.log
console.log(example);
//length
console.log(example.length);
//random number create
var round = 1.5;
rounded = Math.round(round);
console.log(rounded);
//replace string
var pizza = 'pizza is alright';
pizza = pizza.replace('alright', 'wonderful');
console.log(pizza); //pizza is wonderful
//array
var food = ['apple', 'pizza', 'pear'];
console.log(food); //all view
console.log(food[1]); //pizza
//if
var fruit = 'orange';
if (fruit.length > 5 ){
console.log('The fruit name has more than five characters.');
}else{
console.log('The fruit name has five characters or less.');
}
//for
var total = 0;
var limit = 10;
for(var i = 0; i <= limit; i++){
total += i;
}
console.log(total); //55
//function
function math(x, y, z){
return x + (y * z);
}
console.log(math(1, 2, 3)); //7
//number to string
var n = 128;
n = n.toString();
console.log(n);
//object
var pizza = {
toppings: ['cheese', 'sauce', 'pepperoni'],
crust: 'deep dish',
serves: 2
}
console.log(pizza);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment