我自己尝试了这个,但它显示错误,这段代码有什么问题? [英] I tried this by own but it is showing error, what is the problem with this code?

查看:53
本文介绍了我自己尝试了这个,但它显示错误,这段代码有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<!doctype html>





< title>循环!



















var w = 3;

var x = 4;

var y = 5;

var z = 6;

函数add(w,x,y,z){return var total =(w + x + y + z);}

提醒(加);















我的尝试:



当我练习时我正在学习Javascript我遇到了这种情况。

解决方案

你甚至没有调用javascript来查看你的代码或数据。



你真的需要一个非常基础的教程来帮助你走上任何一条道路。



尝试:这个 [ ^ ],对我有用。



从提交的外观来看,你真的应该通过HTML教程(做那个)首先)。


更正,检查内联评论

<!DOCTYPE html> 
< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< script>
var a = 3;
var b = 4;
var c = 5;
var d = 6;
函数add(w,x,y,z){
var total =(w + x + y + z);
总回报; //返回变量,而不是变量声明
}
alert(add(a,b,c,d)); //传递参数
< / script>
< / head>
< body>

< / body>
< / html>



我已重命名变量以便更好地理解。有关Javascript范围的更多信息,请参阅此 JavaScript范围 [ ^ ]

JavaScript函数调用 [ ^


<!doctype html>


<title>Loops!









var w = 3;
var x = 4;
var y = 5;
var z = 6;
function add(w,x,y,z){ return var total=(w+x+y+z);}
alert(add);







What I have tried:

I am learning Javascript when I was practicing I stuck in this situation.

解决方案

Your not even "invoking" javascript to look at your code or data.

You really need a very basic tutorial to get you on any kind of path.

Try:
This[^], which worked for me.

From the looks of your submission, you really should go through the HTML tutorial, as well (do that first).


correction, check the inline comments

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script>
        var a = 3;
        var b = 4;
        var c = 5;
        var d = 6;
        function add(w, x, y, z) {
            var total = (w + x + y + z);
            return total;  // return the variable, instead of variable declaration
        }
        alert(add(a,b,c,d)); // pass the parameters
    </script>
</head>
<body>

</body>
</html>


I have renamed the variables for better understanding. for more information on Javascript scopes refer this JavaScript Scope[^]
JavaScript Function Invocation[^]


这篇关于我自己尝试了这个,但它显示错误,这段代码有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆