day4- JS

python

name = '123'

age = 23

print(f '姓名: {name}')
JS
<script>
window.alert(`你好,${name}!`)
document.write(`<h1>你好,${name}!</h1>`)

typeof
     #判断类型
     #JavaScript中还可以使用const关键字定义常量
     //JavaScript中定义变量可以使用var或let关键字
    //变量的命名跟python的变量命名规则相同,除了可以使用$
    //变量可以大致分为基本数据类型和对象类型(object)两大类
    //基本数据类型包括:number boolean string null undefined symbol
    //用typeof 判断数据类型
    //JavaScript中还可以使用const关键字定义常量
    //算术运算: +-*/  % **
    //比较运算: == != > < >= <= === !==
    //逻辑运算: && (and) ||(or) !(not)
    let stu = {name:'zeng', age:23}
    stu.name
    "zeng"
    stu.age
    23

    let name = prompt('请输入你的名字:')
            if (!!name && name.trim() != '') {
                alert(`你好, ${name}`)
            } else {
                alert('大家好!')
            }


let year = parseInt(prompt('请输入年份:'))
            if (year%4 == 0 && year%100 != 0 || year % 400 == 0) {
                alert(`${year}是闰年`)
            } else {
                alert('不是闰年')
            }
let year = parseInt(prompt('请输入年份:'))
            let isLeap = year%4 == 0 && year%100 != 0 
                || year % 400 == 0          
            alert(`${year}年${isLeap?'是':'不是'}闰年`)

#for循环
            let total = 0
            for (let i = 1; i <= 100; i += 1) {
                total += i
            }
            document.write(total)
            
#while循环    
            let total = 0
            i = 1
            while (i <= 100) {
                total += i
                i += 1
            }
            document.write(total)
#do while循环         
            let total = 0
            i = 1
            do {
                total += i
                i += 1
            } while (i <= 100)
            document.write(total)
</script>
            // 变量数组元素
            let nums = [1, 2, 3, 4, 5]
            // for (let idx = 0; idx < nums.length; idx += 1) {
            //  alert(nums[idx])
            // }
            for (num of nums) {
                alert(num)
            }
            
            // 遍历对象属性
            let stu = {
                name: 'Z',
                age:44,
                sex:'男',
                friends:['h', 'y'],
                car: {
                    'brand': 'QQ',
                    'maxSpeed':'55'
                }
            }
            for (prop in stu) {
                alert(stu[prop])
            }

乘法表

      for ( let i = 1; i <= 9; i += 1) {
                document.write('<p>')
                for (let j = 1; j <= i; j += 1) {
                    document.write(`${i}&times;${j}=${i * j}&nbsp;&nbsp;`)
                }
                document.write('</p>')
            }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 有chole的聚会,也不是因为怕我担心不去的吧。因为你当时应该在上海出差。
    ___________end阅读 1,517评论 0 0
  • 大学四年,匆匆地已度过了大半。大三,课就要修完了,考研的备考,不考研如我过不久就要滚蛋了,回首过去两年多,...
    爱学习的人阅读 1,886评论 14 0
  • 坚持写作的第15天,我说不出来为什么爱你,但我知道,这是我不爱别人的原因。 其实今天想和大家分享的已经很明显了...
    黑子周阅读 1,504评论 0 1
  • 有好多朋友觉得,我就是从事心理咨询这个行业的,所以常会推荐我给他身边有烦恼的朋友。 可是大多数陌生朋友加上微信就会...
    阎渝锦阅读 4,110评论 0 3
  • 向来缘浅,奈何情深。 不知道大家有没有听过一首歌,歌名叫《以后的以后》。里面有一句歌词,“以后的以后...
    爱兰EllenTam阅读 3,517评论 0 1

友情链接更多精彩内容